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.
auto listChangedSinceRead () const -> bool
 Whether the folder's recipient list reads differently now from when loadRecipients() read it: a pull, a sync or another program changed it while the dialog was open.
void showRecipientWarning (const QString &text, const QString &name=QStringLiteral("recipientWarning"))
 Show text above the key list in bold red, for a recipient list that could not be verified.
void showNestedLists ()
 Name the folders below this one that have a recipient list of their own: saving here does not change theirs, so someone removed here can still read what is in them. Folders below that cannot be read are named too, since whether they have one is unknown.
void selectRecipients (const QStringList &listed)
 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. A line that names a key by a subkey or a secondary user ID ticks that key, so unticking it removes the line too.
void keepAsWritten (const QString &line, const QString &why)
 List line as a ticked row of its own, named by why, so OK writes it back as it was.
auto tickReached (const QStringList &ids, const QStringList &lines) -> bool
 Tick the rows of the keys ids, which a probe of lines reached. A key on more than one row (a shared subkey) is ticked only by a line naming its own primary key; other lines are kept as written.
auto setAsideHeldTwice (QStringList *recipients) -> bool
 Keep as written, and warn about, the lines a key ID or fingerprint names that two key blocks hold, or every line when the keyring cannot be listed; those lines leave recipients.
auto probeEachLine (QStringList *recipients) -> bool
 After gpg refused the list as a whole, probe each line on its own (address and name lines first, at most ten), tick what each reaches, and keep the lines gpg cannot encrypt to as written.
void searchKeyring (const QStringList &recipients)
 Tick the keys a keyring search resolves recipients to, and list the lines no key answers to, or that were not looked up, as rows of their own.
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: the user ID and key ID on a line each, each cut to 256 characters (the row only shows them).
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
bool m_listRead = false
int m_readState = 0
QStringList m_readRecipients
 The recipients the list named when the dialog read it.
QString m_lastFilter
QSet< QString > m_notLookedUp
 .gpg-id lines selectRecipients() listed unticked without asking gpg. They are shown without "Show unusable keys", so OK does not drop them unseen.
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 36 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 41 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 40 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 44 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 594 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 799 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: the user ID and key ID on a line each, each cut to 256 characters (the row only shows them).

Parameters
userUser info.
Returns
Formatted text.

Definition at line 781 of file usersdialog.cpp.

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

◆ connectSignals()

void UsersDialog::connectSignals ( )
private

Connect dialog signals.

Definition at line 65 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 642 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 746 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 663 of file usersdialog.cpp.

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

◆ keepAsWritten()

void UsersDialog::keepAsWritten ( const QString & line,
const QString & why )
private

List line as a ticked row of its own, named by why, so OK writes it back as it was.

Parameters
lineThe .gpg-id line.
whyWhy it is kept as written, shown after " ?? ".

Definition at line 362 of file usersdialog.cpp.

Here is the caller graph for this function:

◆ keyPressEvent()

void UsersDialog::keyPressEvent ( QKeyEvent * event)
overrideprotected

Handle key press.

Parameters
eventKey event.

Definition at line 653 of file usersdialog.cpp.

◆ listChangedSinceRead()

auto UsersDialog::listChangedSinceRead ( ) const -> bool
nodiscardprivate

Whether the folder's recipient list reads differently now from when loadRecipients() read it: a pull, a sync or another program changed it while the dialog was open.

Returns
True when the state or the recipients differ.

Definition at line 587 of file usersdialog.cpp.

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

◆ 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 81 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 560 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 96 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 839 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 856 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 835 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 730 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 684 of file usersdialog.cpp.

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

◆ probeEachLine()

auto UsersDialog::probeEachLine ( QStringList * recipients) -> bool
private

After gpg refused the list as a whole, probe each line on its own (address and name lines first, at most ten), tick what each reaches, and keep the lines gpg cannot encrypt to as written.

Parameters
recipientsThe lines still to settle; left holding the ones a probe could not settle.
Returns
Whether any line is left for the keyring search.

Definition at line 451 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 77 of file usersdialog.cpp.

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

◆ searchKeyring()

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

Tick the keys a keyring search resolves recipients to, and list the lines no key answers to, or that were not looked up, as rows of their own.

Parameters
recipientsThe lines a probe could not settle.

Definition at line 484 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 84 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 841 of file usersdialog.cpp.

Here is the caller graph for this function:

◆ selectRecipients()

void UsersDialog::selectRecipients ( const QStringList & listed)
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. A line that names a key by a subkey or a secondary user ID ticks that key, so unticking it removes the line too.

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

Definition at line 330 of file usersdialog.cpp.

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

◆ setAsideHeldTwice()

auto UsersDialog::setAsideHeldTwice ( QStringList * recipients) -> bool
private

Keep as written, and warn about, the lines a key ID or fingerprint names that two key blocks hold, or every line when the keyring cannot be listed; those lines leave recipients.

Parameters
recipientsThe lines still to settle; updated.
Returns
Whether any line is left to settle.

Definition at line 427 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 78 of file usersdialog.h.

Here is the caller graph for this function:

◆ showNestedLists()

void UsersDialog::showNestedLists ( )
private

Name the folders below this one that have a recipient list of their own: saving here does not change theirs, so someone removed here can still read what is in them. Folders below that cannot be read are named too, since whether they have one is unknown.

Definition at line 143 of file usersdialog.cpp.

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

◆ showRecipientWarning()

void UsersDialog::showRecipientWarning ( const QString & text,
const QString & name = QStringLiteral("recipientWarning") )
private

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

Parameters
textThe warning, plain text.
nameThe banner's object name.

Definition at line 109 of file usersdialog.cpp.

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

◆ tickReached()

auto UsersDialog::tickReached ( const QStringList & ids,
const QStringList & lines ) -> bool
private

Tick the rows of the keys ids, which a probe of lines reached. A key on more than one row (a shared subkey) is ticked only by a line naming its own primary key; other lines are kept as written.

Parameters
idsThe key IDs the probe reached.
linesThe lines that were probed.
Returns
false, ticking nothing, when one of ids has no row.

Definition at line 379 of file usersdialog.cpp.

Here is the call graph for this function:
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 647 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 164 of file usersdialog.h.

◆ m_cachedDateTimeValid

bool UsersDialog::m_cachedDateTimeValid
mutableprivate
Initial value:
=
false

Whether cached date/time is valid

Definition at line 166 of file usersdialog.h.

◆ m_cachedNameFilter

QRegularExpression UsersDialog::m_cachedNameFilter
private

Cached regex filter

Definition at line 163 of file usersdialog.h.

◆ m_cachedPatternString

QString UsersDialog::m_cachedPatternString
private

Cached pattern string

Definition at line 162 of file usersdialog.h.

◆ m_dir

QString UsersDialog::m_dir
private

Password store directory

Definition at line 144 of file usersdialog.h.

◆ m_gpgExe

QString UsersDialog::m_gpgExe
private

GPG executable path

Definition at line 139 of file usersdialog.h.

◆ m_initOnAccept

bool UsersDialog::m_initOnAccept {true}
private

Whether accept() runs Pass::Init.

Definition at line 141 of file usersdialog.h.

◆ m_lastFilter

QString UsersDialog::m_lastFilter
private

Last filter text for caching

Definition at line 155 of file usersdialog.h.

◆ m_listRead

bool UsersDialog::m_listRead = false
private

Whether loadRecipients() read the folder's list, so accept() has something to compare the list on disk with.

Definition at line 148 of file usersdialog.h.

◆ m_notLookedUp

QSet<QString> UsersDialog::m_notLookedUp
private

.gpg-id lines selectRecipients() listed unticked without asking gpg. They are shown without "Show unusable keys", so OK does not drop them unseen.

Definition at line 161 of file usersdialog.h.

◆ m_pass

Pass* UsersDialog::m_pass
private

Active Pass backend

Definition at line 137 of file usersdialog.h.

◆ m_passStore

QString UsersDialog::m_passStore
private

Password store root path

Definition at line 138 of file usersdialog.h.

◆ m_preselect

Preselect UsersDialog::m_preselect = Preselect::FromList
private

What opens ticked

Definition at line 145 of file usersdialog.h.

◆ m_readRecipients

QStringList UsersDialog::m_readRecipients
private

The recipients the list named when the dialog read it.

Definition at line 154 of file usersdialog.h.

◆ m_readState

int UsersDialog::m_readState = 0
private

How the list stood up when the dialog read it: a Pass::RecipientsForEditing::State, kept as its value since Pass is only declared here.

Definition at line 152 of file usersdialog.h.

◆ m_userList

QList<UserInfo> UsersDialog::m_userList
private

List of available GPG users

Definition at line 140 of file usersdialog.h.

◆ ui

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

The widgets from usersdialog.ui.

Definition at line 136 of file usersdialog.h.


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