QtPass 1.6.0
Multi-platform GUI for pass, the standard unix password manager.
Loading...
Searching...
No Matches
Util Class Reference

Static utility functions implementation. More...

#include <util.h>

Static Public Member Functions

static auto findBinaryInPath (QString binary) -> QString
 Locate an executable by searching the process PATH and (on Windows) falling back to WSL.
static auto findPasswordStore () -> QString
 Locate the password store directory.
static auto normalizeFolderPath (const QString &path) -> QString
 Ensure a folder path always ends with the native directory separator.
static auto configIsValid () -> bool
 Verify that the required configuration is complete.
static auto getDir (const QModelIndex &index, bool forPass, const QFileSystemModel &model, const StoreModel &storeModel) -> QString
 Get the selected folder path, either relative to the configured pass store or absolute.
static auto endsWithGpg () -> const QRegularExpression &
 Returns a regex to match .gpg file extensions.
static auto protocolRegex () -> const QRegularExpression &
 Returns a regex to match URL protocols.
static auto newLinesRegex () -> const QRegularExpression &
 Returns a regex to match newline characters.
static auto isValidKeyId (const QString &keyId) -> bool
 Check if a string looks like a valid GPG key ID. Validates a GPG key ID after normalization:

Detailed Description

Static utility functions implementation.

Some static utilities to be used elsewhere.

Implementation of utility functions for path handling, binary discovery, and configuration validation.

See also
util.h

Definition at line 20 of file util.h.

Member Function Documentation

◆ configIsValid()

auto Util::configIsValid ( ) -> bool
static

Verify that the required configuration is complete.

Returns
bool true if the password store's .gpg-id exists AND the configured executable (pass or gpg, depending on settings) exists or is a WSL wrapper; false otherwise.
Examples
/home/annejan/Projects/QtPass/src/configdialog.cpp, /home/annejan/Projects/QtPass/src/mainwindow.cpp, and /home/annejan/Projects/QtPass/src/util.cpp.

Definition at line 188 of file util.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ endsWithGpg()

auto Util::endsWithGpg ( ) -> const QRegularExpression &
static

Returns a regex to match .gpg file extensions.

Returns
Reference to static regex
Examples
/home/annejan/Projects/QtPass/src/imitatepass.cpp, /home/annejan/Projects/QtPass/src/mainwindow.cpp, and /home/annejan/Projects/QtPass/src/util.cpp.

Definition at line 249 of file util.cpp.

Here is the caller graph for this function:

◆ findBinaryInPath()

auto Util::findBinaryInPath ( QString binary) -> QString
static

Locate an executable by searching the process PATH and (on Windows) falling back to WSL.

Parameters
binaryExecutable name or relative path to locate (e.g., "gpg" or "pass").
Returns
QString Absolute path to the executable if found, empty QString otherwise.
Examples
/home/annejan/Projects/QtPass/src/configdialog.cpp, /home/annejan/Projects/QtPass/src/qtpasssettings.cpp, and /home/annejan/Projects/QtPass/src/util.cpp.

Definition at line 120 of file util.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ findPasswordStore()

auto Util::findPasswordStore ( ) -> QString
static

Locate the password store directory.

Resolves the path to the password store directory.

Returns
QString Path to the password store, always ends with native directory separator.

Initializes the environment, checks for the
PASSWORD_STORE_DIR
variable, and falls back to a platform-specific default location under the user's home directory.

Returns
QString - Normalized path to the password store folder.
Examples
/home/annejan/Projects/QtPass/src/mainwindow.cpp, and /home/annejan/Projects/QtPass/src/util.cpp.

Definition at line 77 of file util.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getDir()

auto Util::getDir ( const QModelIndex & index,
bool forPass,
const QFileSystemModel & model,
const StoreModel & storeModel ) -> QString
static

Get the selected folder path, either relative to the configured pass store or absolute.

Parameters
indexModel index selecting the file or folder.
forPassIf true, return the path relative to the pass store; otherwise return an absolute path.
modelFilesystem model used to resolve the index.
storeModelStoreModel used to map view indexes to the filesystem model.
Returns
QString Folder path that always ends with the native directory separator. Returns an empty string when index is invalid and forPass is true; otherwise returns the pass store root.
Examples
/home/annejan/Projects/QtPass/src/mainwindow.cpp, and /home/annejan/Projects/QtPass/src/util.cpp.

Definition at line 231 of file util.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isValidKeyId()

auto Util::isValidKeyId ( const QString & keyId) -> bool
static

Check if a string looks like a valid GPG key ID. Validates a GPG key ID after normalization:

  • Strips optional 0x/0X prefix
  • Strips surrounding angle brackets <...>
  • Strips leading @, /, #, or & prefix
  • Validates remaining string is 8-40 hex characters (0-9, A-F, a-f)
    Parameters
    keyIdThe string to validate.
    Returns
    true if the key ID format is valid, false otherwise.
Examples
/home/annejan/Projects/QtPass/src/pass.cpp, and /home/annejan/Projects/QtPass/src/util.cpp.

Definition at line 277 of file util.cpp.

Here is the caller graph for this function:

◆ newLinesRegex()

auto Util::newLinesRegex ( ) -> const QRegularExpression &
static

Returns a regex to match newline characters.

Returns
Reference to static regex
Examples
/home/annejan/Projects/QtPass/src/imitatepass.cpp, and /home/annejan/Projects/QtPass/src/util.cpp.

Definition at line 272 of file util.cpp.

Here is the caller graph for this function:

◆ normalizeFolderPath()

auto Util::normalizeFolderPath ( const QString & path) -> QString
static

Ensure a folder path always ends with the native directory separator.

Parameters
pathThe folder path to normalize.
Returns
QString Path with trailing separator added if missing.
Examples
/home/annejan/Projects/QtPass/src/configdialog.cpp, and /home/annejan/Projects/QtPass/src/util.cpp.

Definition at line 94 of file util.cpp.

Here is the caller graph for this function:

◆ protocolRegex()

auto Util::protocolRegex ( ) -> const QRegularExpression &
static

Returns a regex to match URL protocols.

Returns a regex matching common remote/network protocol schemes.

Returns
Reference to static regex

Matches http://, https://, ftp://, ftps://, ssh://, sftp://, webdav://, webdavs://

Note: Local file URLs (file:///) are intentionally excluded by design, as they represent local paths rather than network protocols. If this behavior needs to change, update both this function and the corresponding test.

Returns
QRegularExpression reference
Examples
/home/annejan/Projects/QtPass/src/mainwindow.cpp, and /home/annejan/Projects/QtPass/src/util.cpp.

Definition at line 266 of file util.cpp.


The documentation for this class was generated from the following files: