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

Renders decrypted password-file fields into MainWindow's grid. More...

#include <passworddisplaypanel.h>

Inheritance diagram for PasswordDisplayPanel:
Collaboration diagram for PasswordDisplayPanel:

Signals

void copyRequested (const QString &text)
 Emitted when a field's copy button is clicked.
void textCopied (const QString &text)
 Text was selected and copied out of a field's value (Ctrl+C, the context menu, a drag, or the X11 primary selection); it is already on the clipboard and only needs tracking for autoclear.
void qrRequested (const QString &text)
 Emitted when a field's QR button is clicked.
void editRequested ()
 Emitted on a double-click anywhere on a field row: the user wants to change what they are looking at.

Public Member Functions

 PasswordDisplayPanel (QGridLayout *grid, QBoxLayout *container, QWidget *widgetParent, QObject *parent=nullptr)
 Construct a panel that renders into the given layouts.
void clear ()
 Remove all field rows and collapse the container spacing.
void refreshPalette ()
 Re-derive palette-dependent styling after a runtime theme change.
void displayFields (const QString &password, const NamedValues &namedValues, const AppSettings &s, const QString &otpConfig={})
 Render the password and template fields of a decrypted entry.
auto currentOtpCode () const -> QString
 The one-time password currently on display, if there is one.
void setMarkedSecrets (const QStringList &names)
 Set the field names a template marks as secret.
auto isSecret (const QString &field, const AppSettings &s) const -> bool
 Whether a field is a secret "Hide password" hides: one a template marks (setMarkedSecrets()), or, with "Also hide other secrets", one whose name holds a secret word. Not the password itself, nor every field under "Hide every field". False with "Hide password" off.

Protected Member Functions

auto eventFilter (QObject *watched, QEvent *event) -> bool override
 Turn a left double-click on a field row into editRequested().

Private Member Functions

void addField (int position, const QString &field, const QString &value, const AppSettings &s)
 Render one name: value row: action buttons, then the value either behind the eye button (see hides()) or in a read-only browser that links http(s) URLs, then the name label.
void addRow (int position, QLabel *label, QFrame *frame)
 Put a row's label and value frame into the grid, listening for a double-click on either (and on the frame's children, which swallow mouse events first).
void addOtpField (int position, const QString &otpConfig, const AppSettings &s)
 Render the live OTP row: an OtpCodeWidget in a field frame under an "OTP code" label. A configuration Totp::parse() rejects becomes an inert message row with no copy or QR button. The code is never hidden and never offered as a QR code.
auto createFieldFrame () -> QFrame *
 New bordered frame with a tight horizontal layout, styled by applyFrameStyle(); shared by addField() and addOtpField() so the rows cannot drift apart.
void addActionButtons (QLayout *layout, const QString &field, const QString &value, const AppSettings &s)
 Add the copy, QR and open-in-browser buttons a field gets, per the settings.
void addHiddenPassword (QLayout *layout, const QString &field, const QString &value, const QString &lineStyle)
 Add the password, hidden, with a button that shows it.
void applyFrameStyle (QFrame *frame) const
 Give a field frame its rounded border in the current QPalette::Mid colour. The colour is baked into the stylesheet, so refreshPalette() re-runs this after a theme change.
auto hides (const QString &field, const AppSettings &s) const -> bool
 Whether a field is shown behind the eye button: the password, a field a template marks, every field with "Hide every field", or one whose name holds a secret word with "Also hide other secrets". Only with "Hide password" on.

Private Attributes

QStringList m_markedSecrets
 Field names the current template marks as secret, compared case-insensitively in isSecret(); set by setMarkedSecrets().
QGridLayout * m_grid
 The grid the rows go into; owned by MainWindow's .ui.
QBoxLayout * m_container
 Layout around the grid whose spacing is 0 while empty and 6 once rows are shown; owned by MainWindow's .ui.
QWidget * m_widgetParent
 Parent for the buttons the panel creates and source of the palette used by applyFrameStyle(); not owned.

Detailed Description

Renders decrypted password-file fields into MainWindow's grid.

Extracted from MainWindow, where the field-rendering and grid-clearing logic was spread across addToGridLayout(), clearTemplateWidgets() and passShowHandler()/otpFromFileToClipboard(). It builds the per-field row (optional copy / QR / open-in-browser buttons plus a value widget with password echo handling) and owns the show/hide spacing of the surrounding container.

It does not own the grid or container widgets (those live in MainWindow's .ui); it renders into the ones it is given. Copy and QR actions are surfaced as signals rather than wired to QtPass directly, so the panel has no dependency on the application object and is unit-testable on its own.

Definition at line 43 of file passworddisplaypanel.h.

Constructor & Destructor Documentation

◆ PasswordDisplayPanel()

PasswordDisplayPanel::PasswordDisplayPanel ( QGridLayout * grid,
QBoxLayout * container,
QWidget * widgetParent,
QObject * parent = nullptr )

Construct a panel that renders into the given layouts.

Parameters
gridGrid layout that receives the field rows.
containerSurrounding box layout whose spacing is toggled.
widgetParentParent widget for the created field widgets.
parentQObject parent.

Definition at line 36 of file passworddisplaypanel.cpp.

Here is the caller graph for this function:

Member Function Documentation

◆ addActionButtons()

void PasswordDisplayPanel::addActionButtons ( QLayout * layout,
const QString & field,
const QString & value,
const AppSettings & s )
private

Add the copy, QR and open-in-browser buttons a field gets, per the settings.

Parameters
layoutThe field's frame layout.
fieldThe field's name, trimmed.
valueIts value, trimmed.
sClipboard and qrencode settings.

Definition at line 219 of file passworddisplaypanel.cpp.

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

◆ addField()

void PasswordDisplayPanel::addField ( int position,
const QString & field,
const QString & value,
const AppSettings & s )
private

Render one name: value row: action buttons, then the value either behind the eye button (see hides()) or in a read-only browser that links http(s) URLs, then the name label.

The password row keeps its value verbatim (only a trailing CR is dropped); every other value is trimmed.

Parameters
positionGrid row to fill.
fieldThe field's name; trimmed here.
valueThe raw value.
sDisplay settings (clipboard, qrencode, monospace, hiding).

Definition at line 270 of file passworddisplaypanel.cpp.

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

◆ addHiddenPassword()

void PasswordDisplayPanel::addHiddenPassword ( QLayout * layout,
const QString & field,
const QString & value,
const QString & lineStyle )
private

Add the password, hidden, with a button that shows it.

Parameters
layoutThe field's frame layout.
fieldThe field's name, trimmed.
valueThe password.
lineStyleThe style for the value widget.

Definition at line 247 of file passworddisplaypanel.cpp.

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

◆ addOtpField()

void PasswordDisplayPanel::addOtpField ( int position,
const QString & otpConfig,
const AppSettings & s )
private

Render the live OTP row: an OtpCodeWidget in a field frame under an "OTP code" label. A configuration Totp::parse() rejects becomes an inert message row with no copy or QR button. The code is never hidden and never offered as a QR code.

Parameters
positionGrid row to fill.
otpConfigRaw OTP configuration from the entry.
sDisplay settings (clipboard, monospace).

Definition at line 371 of file passworddisplaypanel.cpp.

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

◆ addRow()

void PasswordDisplayPanel::addRow ( int position,
QLabel * label,
QFrame * frame )
private

Put a row's label and value frame into the grid, listening for a double-click on either (and on the frame's children, which swallow mouse events first).

Parameters
positionGrid row.
labelThe name label for column 0.
frameThe value frame for column 1.

Definition at line 316 of file passworddisplaypanel.cpp.

Here is the caller graph for this function:

◆ applyFrameStyle()

void PasswordDisplayPanel::applyFrameStyle ( QFrame * frame) const
private

Give a field frame its rounded border in the current QPalette::Mid colour. The colour is baked into the stylesheet, so refreshPalette() re-runs this after a theme change.

Parameters
frameThe frame to style.

Definition at line 339 of file passworddisplaypanel.cpp.

Here is the caller graph for this function:

◆ clear()

void PasswordDisplayPanel::clear ( )

Remove all field rows and collapse the container spacing.

Definition at line 43 of file passworddisplaypanel.cpp.

Here is the caller graph for this function:

◆ copyRequested

void PasswordDisplayPanel::copyRequested ( const QString & text)
signal

Emitted when a field's copy button is clicked.

Parameters
textValue to copy to the clipboard.
Here is the caller graph for this function:

◆ createFieldFrame()

auto PasswordDisplayPanel::createFieldFrame ( ) -> QFrame *
private

New bordered frame with a tight horizontal layout, styled by applyFrameStyle(); shared by addField() and addOtpField() so the rows cannot drift apart.

Returns
The frame; the caller adds it to the grid.

Definition at line 357 of file passworddisplaypanel.cpp.

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

◆ currentOtpCode()

auto PasswordDisplayPanel::currentOtpCode ( ) const -> QString
nodiscard

The one-time password currently on display, if there is one.

Lets callers copy the code the user can actually see instead of decrypting the entry a second time to re-derive it.

Returns
The live code, or an empty string when no OTP row is rendered (no OTP in the entry, OTP support off, or the panel was cleared).

Definition at line 69 of file passworddisplaypanel.cpp.

Here is the caller graph for this function:

◆ displayFields()

void PasswordDisplayPanel::displayFields ( const QString & password,
const NamedValues & namedValues,
const AppSettings & s,
const QString & otpConfig = {} )

Render the password and template fields of a decrypted entry.

Fields whose name satisfies FileContent::isOtpFieldName() are never rendered verbatim, because their value is a TOTP shared secret. When otpConfig is set, a live OtpCodeWidget row is rendered in that field's place instead (or appended, when the configuration came from the entry body rather than from a field).

Parameters
passwordPassword value (row 0); skipped when empty.
namedValuesTemplate/named fields to render below the password.
sAppSettings snapshot supplying display settings (clipboard, monospace, hide-password, qrencode).
otpConfigRaw OTP configuration from FileContent::getOtpUri(), or an empty string to render no OTP row at all.

Definition at line 83 of file passworddisplaypanel.cpp.

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

◆ editRequested

void PasswordDisplayPanel::editRequested ( )
signal

Emitted on a double-click anywhere on a field row: the user wants to change what they are looking at.

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

◆ eventFilter()

auto PasswordDisplayPanel::eventFilter ( QObject * watched,
QEvent * event ) -> bool
overrideprotected

Turn a left double-click on a field row into editRequested().

Parameters
watchedthe row's label or value frame
eventthe event to inspect
Returns
true when the double-click was consumed

Definition at line 327 of file passworddisplaypanel.cpp.

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

◆ hides()

auto PasswordDisplayPanel::hides ( const QString & field,
const AppSettings & s ) const -> bool
nodiscardprivate

Whether a field is shown behind the eye button: the password, a field a template marks, every field with "Hide every field", or one whose name holds a secret word with "Also hide other secrets". Only with "Hide password" on.

Parameters
fieldThe field's name, trimmed.
sThe display settings.
Returns
true to hide the value.

Definition at line 198 of file passworddisplaypanel.cpp.

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

◆ isSecret()

auto PasswordDisplayPanel::isSecret ( const QString & field,
const AppSettings & s ) const -> bool
nodiscard

Whether a field is a secret "Hide password" hides: one a template marks (setMarkedSecrets()), or, with "Also hide other secrets", one whose name holds a secret word. Not the password itself, nor every field under "Hide every field". False with "Hide password" off.

Parameters
fieldThe field's name, trimmed.
sThe display settings.
Returns
true for a secret to hide.

Definition at line 205 of file passworddisplaypanel.cpp.

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

◆ qrRequested

void PasswordDisplayPanel::qrRequested ( const QString & text)
signal

Emitted when a field's QR button is clicked.

Parameters
textValue to render as a QR code.
Here is the caller graph for this function:

◆ refreshPalette()

void PasswordDisplayPanel::refreshPalette ( )

Re-derive palette-dependent styling after a runtime theme change.

Field frames bake the current QPalette::Mid colour into a stylesheet; call this on QEvent::PaletteChange so an entry that is already on screen picks up the new theme instead of keeping the old border.

Definition at line 347 of file passworddisplaypanel.cpp.

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

◆ setMarkedSecrets()

void PasswordDisplayPanel::setMarkedSecrets ( const QStringList & names)

Set the field names a template marks as secret.

With "Hide password" on, a field with one of these names, whole and in any case, is hidden like the password, whatever "Also hide other secrets" says: the template's writer asked for it. Kept until set again.

Parameters
namesThe names from TemplateIO::secretFieldsIn() and TemplateIO::readSecretFields().

Definition at line 194 of file passworddisplaypanel.cpp.

Here is the caller graph for this function:

◆ textCopied

void PasswordDisplayPanel::textCopied ( const QString & text)
signal

Text was selected and copied out of a field's value (Ctrl+C, the context menu, a drag, or the X11 primary selection); it is already on the clipboard and only needs tracking for autoclear.

Parameters
textThe copied text.
Here is the caller graph for this function:

Member Data Documentation

◆ m_container

QBoxLayout* PasswordDisplayPanel::m_container
private

Layout around the grid whose spacing is 0 while empty and 6 once rows are shown; owned by MainWindow's .ui.

Definition at line 248 of file passworddisplaypanel.h.

◆ m_grid

QGridLayout* PasswordDisplayPanel::m_grid
private

The grid the rows go into; owned by MainWindow's .ui.

Definition at line 243 of file passworddisplaypanel.h.

◆ m_markedSecrets

QStringList PasswordDisplayPanel::m_markedSecrets
private

Field names the current template marks as secret, compared case-insensitively in isSecret(); set by setMarkedSecrets().

Definition at line 241 of file passworddisplaypanel.h.

◆ m_widgetParent

QWidget* PasswordDisplayPanel::m_widgetParent
private

Parent for the buttons the panel creates and source of the palette used by applyFrameStyle(); not owned.

Definition at line 253 of file passworddisplaypanel.h.


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