QtPass 2.0.0
Developer documentation
Loading...
Searching...
No Matches
UsersDialog Class Reference

Dialog for selecting GPG recipients for password encryption. More...

#include <usersdialog.h>

Inheritance diagram for UsersDialog:
Collaboration diagram for UsersDialog:

Public Types

enum class  Preselect { FromList , Nothing }
 Whether the recipients on disk are ticked when it opens. More...

Public Slots

void accept () override
 Handle dialog acceptance.

Public Member Functions

 UsersDialog (Pass *pass, const AppSettings &s, QString dir, QWidget *parent=nullptr)
 Construct users dialog.
 UsersDialog (Pass *pass, const AppSettings &s, QString dir, Preselect preselect, QWidget *parent=nullptr)
 Construct users dialog, saying what to preselect.
 ~UsersDialog () override
 Destroys the dialog and its generated form.
void setInitOnAccept (bool initOnAccept)
 Choose whether OK runs Pass::Init on the folder.
auto selectedUsers () const -> QList< UserInfo >
 The key list with the user's choice in each entry's enabled flag.
auto hasSelection () const -> bool
 Whether at least one key is ticked.

Protected Member Functions

void keyPressEvent (QKeyEvent *event) override
 Handle key press.

Private Slots

void itemChange (QListWidgetItem *item)
 Handle user selection change.
void on_lineEdit_textChanged (const QString &filter)
 Filter user list.
void on_checkBox_clicked ()
 Handle select all checkbox.
void on_importKeyButton_clicked ()
 Import a GPG key and refresh the list.
void selectImportedKey (const QString &importedKey)
 Make the key gpg just imported the current row. gpg reports a 16-character long ID (IMPORTED) or a 40-character fingerprint (IMPORT_OK), so the two are compared both ways, by suffix.

Private Member Functions

void updateOkButton ()
 Enable OK only while at least one key is ticked (hasSelection()).
void restoreDialogState ()
void connectSignals ()
 Connect dialog signals.
auto loadGpgKeys () -> bool
 Load GPG keys and determine secret key status.
void markSecretKeys (QList< UserInfo > &users)
 Mark which keys have secret counterparts.
void loadRecipients ()
 Load recipients and handle missing keys.
void showRecipientWarning (const QString &text)
 Show text above the key list in bold red, for a recipient list that could not be verified.
void selectRecipients (const QStringList &recipients)
 Tick the keys the folder is encrypted to, and list recipients no key in the keyring answers to, so saving does not drop them silently.
void populateList (const QString &filter=QString())
 Populate user list.
bool passesFilter (const UserInfo &user, const QString &filter, const QRegularExpression &nameFilter) const
 Check if user passes filter.
auto isUserExpired (const UserInfo &user) const -> bool
 Check if GPG key is expired.
QString buildUserText (const UserInfo &user) const
 Build display text for user.
void applyUserStyling (QListWidgetItem *item, const UserInfo &user) const
 Apply visual styling to user item.

Private Attributes

QScopedPointer< Ui::UsersDialog > ui
 The widgets from usersdialog.ui.
Pass * m_pass
QString m_passStore
QString m_gpgExe
QList< UserInfo > m_userList
bool m_initOnAccept {true}
QString m_dir
Preselect m_preselect = Preselect::FromList
QString m_lastFilter
QString m_cachedPatternString
QRegularExpression m_cachedNameFilter
QDateTime m_cachedCurrentDateTime
bool m_cachedDateTimeValid

Detailed Description

Dialog for selecting GPG recipients for password encryption.

UsersDialog allows users to select which GPG keys to encrypt passwords to. It displays available keys, supports filtering, and shows key expiration status.

Definition at line 35 of file usersdialog.h.

Member Enumeration Documentation

◆ Preselect

enum class UsersDialog::Preselect
strong

Whether the recipients on disk are ticked when it opens.

Enumerator
FromList 

The folder's recipient list, as the backend reads it.

Nothing 

None: for a store that had no list when it was chosen.

Definition at line 40 of file usersdialog.h.

Constructor & Destructor Documentation

◆ UsersDialog() [1/2]

UsersDialog::UsersDialog ( Pass * pass,
const AppSettings & s,
QString dir,
QWidget * parent = nullptr )
explicit

Construct users dialog.

Parameters
passActive Pass backend.
sApplication settings snapshot.
dirPassword store directory path.
parentParent widget.

Definition at line 34 of file usersdialog.cpp.

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

◆ UsersDialog() [2/2]

UsersDialog::UsersDialog ( Pass * pass,
const AppSettings & s,
QString dir,
Preselect preselect,
QWidget * parent = nullptr )

Construct users dialog, saying what to preselect.

Parameters
passActive Pass backend.
sApplication settings snapshot.
dirPassword store directory path.
preselectWhat is ticked when it opens.
parentParent widget.

Definition at line 38 of file usersdialog.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ accept

void UsersDialog::accept ( )
overrideslot

Handle dialog acceptance.

Definition at line 250 of file usersdialog.cpp.

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

◆ applyUserStyling()

void UsersDialog::applyUserStyling ( QListWidgetItem * item,
const UserInfo & user ) const
private

Apply visual styling to user item.

Parameters
itemList item.
userUser info.

Definition at line 374 of file usersdialog.cpp.

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

◆ buildUserText()

QString UsersDialog::buildUserText ( const UserInfo & user) const
private

Build display text for user.

Parameters
userUser info.
Returns
Formatted text.

Definition at line 361 of file usersdialog.cpp.

Here is the caller graph for this function:

◆ connectSignals()

void UsersDialog::connectSignals ( )
private

Connect dialog signals.

Definition at line 58 of file usersdialog.cpp.

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

◆ hasSelection()

auto UsersDialog::hasSelection ( ) const -> bool
nodiscard

Whether at least one key is ticked.

Returns
true if Init would get a recipient.

Definition at line 263 of file usersdialog.cpp.

Here is the caller graph for this function:

◆ isUserExpired()

auto UsersDialog::isUserExpired ( const UserInfo & user) const -> bool
private

Check if GPG key is expired.

Parameters
userUser to check.
Returns
true if key is expired.

Definition at line 351 of file usersdialog.cpp.

Here is the caller graph for this function:

◆ itemChange

void UsersDialog::itemChange ( QListWidgetItem * item)
privateslot

Handle user selection change.

Parameters
itemChanged list item.

Definition at line 284 of file usersdialog.cpp.

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

◆ keyPressEvent()

void UsersDialog::keyPressEvent ( QKeyEvent * event)
overrideprotected

Handle key press.

Parameters
eventKey event.

Definition at line 274 of file usersdialog.cpp.

◆ loadGpgKeys()

auto UsersDialog::loadGpgKeys ( ) -> bool
private

Load GPG keys and determine secret key status.

Returns
true if successful, false if keys could not be loaded.

Definition at line 74 of file usersdialog.cpp.

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

◆ loadRecipients()

void UsersDialog::loadRecipients ( )
private

Load recipients and handle missing keys.

Definition at line 226 of file usersdialog.cpp.

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

◆ markSecretKeys()

void UsersDialog::markSecretKeys ( QList< UserInfo > & users)
private

Mark which keys have secret counterparts.

Parameters
usersList of users to mark.

Definition at line 89 of file usersdialog.cpp.

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

◆ on_checkBox_clicked

void UsersDialog::on_checkBox_clicked ( )
privateslot

Handle select all checkbox.

Definition at line 414 of file usersdialog.cpp.

Here is the call graph for this function:

◆ on_importKeyButton_clicked

void UsersDialog::on_importKeyButton_clicked ( )
privateslot

Import a GPG key and refresh the list.

Definition at line 437 of file usersdialog.cpp.

Here is the call graph for this function:

◆ on_lineEdit_textChanged

void UsersDialog::on_lineEdit_textChanged ( const QString & filter)
privateslot

Filter user list.

Parameters
filterFilter text.

Definition at line 410 of file usersdialog.cpp.

Here is the call graph for this function:

◆ passesFilter()

bool UsersDialog::passesFilter ( const UserInfo & user,
const QString & filter,
const QRegularExpression & nameFilter ) const
private

Check if user passes filter.

Parameters
userUser to check.
filterText filter.
nameFilterRegex filter.
Returns
true if user passes.

Definition at line 337 of file usersdialog.cpp.

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

◆ populateList()

void UsersDialog::populateList ( const QString & filter = QString())
private

Populate user list.

Parameters
filterOptional filter text.

Definition at line 305 of file usersdialog.cpp.

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

◆ restoreDialogState()

void UsersDialog::restoreDialogState ( )
private

Attach WindowStateStore, which restores the dialog's saved geometry now and saves it under "usersDialog" when the dialog closes.

Definition at line 70 of file usersdialog.cpp.

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

◆ selectedUsers()

auto UsersDialog::selectedUsers ( ) const -> QList< UserInfo >
inlinenodiscard

The key list with the user's choice in each entry's enabled flag.

Returns
All listed users; the selected ones have enabled == true.

Definition at line 83 of file usersdialog.h.

Here is the caller graph for this function:

◆ selectImportedKey

void UsersDialog::selectImportedKey ( const QString & importedKey)
privateslot

Make the key gpg just imported the current row. gpg reports a 16-character long ID (IMPORTED) or a 40-character fingerprint (IMPORT_OK), so the two are compared both ways, by suffix.

Parameters
importedKeyWhat gpg reported.

Definition at line 416 of file usersdialog.cpp.

Here is the caller graph for this function:

◆ selectRecipients()

void UsersDialog::selectRecipients ( const QStringList & recipients)
private

Tick the keys the folder is encrypted to, and list recipients no key in the keyring answers to, so saving does not drop them silently.

Parameters
recipientsThe folder's recipients, as listed in its .gpg-id.

Definition at line 158 of file usersdialog.cpp.

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

◆ setInitOnAccept()

void UsersDialog::setInitOnAccept ( bool initOnAccept)
inline

Choose whether OK runs Pass::Init on the folder.

On by default. Off, the dialog only collects the selection; the caller reads selectedUsers() and initialises the folder itself (new profiles, which must not go through the backend of the active store).

Parameters
initOnAcceptfalse to skip Pass::Init.

Definition at line 77 of file usersdialog.h.

Here is the caller graph for this function:

◆ showRecipientWarning()

void UsersDialog::showRecipientWarning ( const QString & text)
private

Show text above the key list in bold red, for a recipient list that could not be verified.

Parameters
textThe warning, plain text.

Definition at line 102 of file usersdialog.cpp.

Here is the caller graph for this function:

◆ updateOkButton()

void UsersDialog::updateOkButton ( )
private

Enable OK only while at least one key is ticked (hasSelection()).

Definition at line 268 of file usersdialog.cpp.

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

Member Data Documentation

◆ m_cachedCurrentDateTime

QDateTime UsersDialog::m_cachedCurrentDateTime
mutableprivate

Cached current date/time for expiry checks

Definition at line 148 of file usersdialog.h.

◆ m_cachedDateTimeValid

bool UsersDialog::m_cachedDateTimeValid
mutableprivate
Initial value:
=
false

Whether cached date/time is valid

Definition at line 150 of file usersdialog.h.

◆ m_cachedNameFilter

QRegularExpression UsersDialog::m_cachedNameFilter
private

Cached regex filter

Definition at line 147 of file usersdialog.h.

◆ m_cachedPatternString

QString UsersDialog::m_cachedPatternString
private

Cached pattern string

Definition at line 146 of file usersdialog.h.

◆ m_dir

QString UsersDialog::m_dir
private

Password store directory

Definition at line 143 of file usersdialog.h.

◆ m_gpgExe

QString UsersDialog::m_gpgExe
private

GPG executable path

Definition at line 138 of file usersdialog.h.

◆ m_initOnAccept

bool UsersDialog::m_initOnAccept {true}
private

Whether accept() runs Pass::Init.

Definition at line 140 of file usersdialog.h.

◆ m_lastFilter

QString UsersDialog::m_lastFilter
private

Last filter text for caching

Definition at line 145 of file usersdialog.h.

◆ m_pass

Pass* UsersDialog::m_pass
private

Active Pass backend

Definition at line 136 of file usersdialog.h.

◆ m_passStore

QString UsersDialog::m_passStore
private

Password store root path

Definition at line 137 of file usersdialog.h.

◆ m_preselect

Preselect UsersDialog::m_preselect = Preselect::FromList
private

What opens ticked

Definition at line 144 of file usersdialog.h.

◆ m_userList

QList<UserInfo> UsersDialog::m_userList
private

List of available GPG users

Definition at line 139 of file usersdialog.h.

◆ ui

QScopedPointer<Ui::UsersDialog> UsersDialog::ui
private

The widgets from usersdialog.ui.

Definition at line 135 of file usersdialog.h.


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