QtPass 2.0.0
Developer documentation
Loading...
Searching...
No Matches
passworddialog.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2015 Anne Jan Brouwer
2// SPDX-License-Identifier: GPL-3.0-or-later
8#ifndef SRC_PASSWORDDIALOG_H_
9#define SRC_PASSWORDDIALOG_H_
10
11#include "appsettings.h"
12
13#include <QDialog>
14#include <QPointer>
15#include <QScopedPointer>
16
17namespace Ui {
18class PasswordDialog;
19}
20
21class Pass;
22class FieldLabel;
23class QAction;
24class QLineEdit;
25class SecretLineEdit;
26class QShortcut;
27class QWidget;
28
43class PasswordDialog : public QDialog {
44 Q_OBJECT
45
46public:
52 explicit PasswordDialog(PasswordConfiguration passConfig,
53 QWidget *parent = nullptr);
62 PasswordDialog(Pass *pass, const AppSettings &s, QString file,
63 const bool &isNew, QWidget *parent = nullptr);
68 ~PasswordDialog() override;
69
81 void accept() override;
82
89 void reject() override;
90
104 void setNewEntryLocation(const QString &storeRoot, const QStringList &folders,
105 const QString &currentFolder);
106
112 auto entryPath() const -> QString { return m_file; }
113
119 void setPassword(const QString &password);
120
126 auto getPassword() -> QString;
127
133 void setTemplate(const QString &rawFields, bool useTemplate);
134
143 void templateAll(bool templateAll);
144
149 void setLength(int length);
150
155 void setPasswordCharTemplate(int templateIndex);
156
161 void usePwgen(bool usePwgen);
162
168 void setAvailableTemplates(const QHash<QString, QStringList> &templates,
169 const QString &defaultTemplate);
170
171signals:
177 void copied(const QString &text);
178
179public slots:
183 void cycleTemplate();
184
194 void setPass(const QString &output, const QString &file = QString());
195
196private slots:
204 void setPasswordVisible(bool show);
217 void on_rejected();
218
222 void onInsertFinished();
230 void onInsertFailed(const QString &err, bool written);
231
241 void onShowError(int exitCode, const QString &err);
242
243private:
249 void reportCopies(SecretLineEdit *line);
254 [[nodiscard]] auto otpLineEdit() const -> QLineEdit *;
263 void setEditorEnabled(bool enabled);
267 void save();
272 void setSaving(bool saving);
281 auto isOwnInsertReport() -> bool;
287 void showNotSaved(const QString &err);
294 void hookOtpField();
298 void validateOtpField();
309 void markOtpFieldEdited();
316 void normalizeOtpField();
317
319 QScopedPointer<Ui::PasswordDialog> ui;
323 Pass *m_pass{nullptr};
325 QStringList m_fields;
328 QString m_file;
330 QString m_storeRoot;
334
340 auto resolveNewEntry(QString *problem) const -> QString;
346 void validateNewEntry();
356 void renameField(QLineEdit *line, FieldLabel *label, const QString &to);
364 void removeField(QLineEdit *line);
373 bool m_isNew{};
379 bool m_saving{};
388 QList<QLineEdit *> m_templateLines;
391 QList<QLineEdit *> m_otherLines;
394 QHash<QString, QStringList> m_availableTemplates;
398 QShortcut *m_templateShortcut{nullptr};
404 QPointer<QAction> m_otpWarning;
409 QPointer<QLineEdit> m_otpLine;
410
417 void applyTemplate(const QString &templateName);
422 void setupTemplateBox();
423};
424
425#endif // SRC_PASSWORDDIALOG_H_
AppSettings, the value object holding every flat QtPass setting.
The name of a key: value field in PasswordDialog, editable in place: double-click or the context menu...
Definition fieldlabel.h:26
Abstract base class for password store operations.
Definition pass.h:75
void validateOtpField()
Flag an OTP value that is neither a URI nor valid base32.
QScopedPointer< Ui::PasswordDialog > ui
Generated form (passworddialog.ui); owned.
bool m_templating
Whether template fields get widgets of their own (the "Use template" setting).
void hookOtpField()
Connect validation and normalisation to the OTP field, if present.
QList< QLineEdit * > m_otherLines
QStringList m_fields
Field names of the current template, in template order.
void onInsertFailed(const QString &err, bool written)
The insert started by accept() failed: unlock the fields, which still hold what was typed,...
void setPassword(const QString &password)
Populate the dialog's password field with the given text.
QString m_newEntryFolder
void setSaving(bool saving)
Lock or unlock the dialog while an insert is in flight.
void validateNewEntry()
Re-runs resolveNewEntry() as the user types or picks a folder: shows the problem (if any) in the stat...
Pass * m_pass
Backend for Show, Insert and generatePassword; not owned.
void cycleTemplate()
Cycle to next template (Ctrl+T).
void setAvailableTemplates(const QHash< QString, QStringList > &templates, const QString &defaultTemplate)
Set available templates from file and select default.
void setupTemplateBox()
Hides the template row until setAvailableTemplates() fills it and wires the combo box so that a user ...
auto entryPath() const -> QString
The entry the dialog writes to, relative to the store and without the .gpg suffix (for example work/v...
void normalizeOtpField()
Rewrite the OTP field as a canonical otpauth URI.
bool m_allFields
Whether every key: value line becomes a field (the "Templateall fields" setting), as given to FileCon...
void showNotSaved(const QString &err)
Say why the entry was not saved and let the user try again; the fields keep what was typed.
void accept() override
OK: for a new entry, resolve and check the name first and stay open when it is not usable; then inser...
auto otpLineEdit() const -> QLineEdit *
Locate the field that holds the one-time password configuration.
void save()
Start inserting what the dialog holds and wait for the result.
PasswordDialog(PasswordConfiguration passConfig, QWidget *parent=nullptr)
Construct a PasswordDialog for entering a new password.
bool m_isNew
True when creating an entry, false when editing one; decides whether the name row and the decrypt-bef...
void setLength(int length)
Set the desired password length shown in the dialog.
void reject() override
Cancel, Esc and the window's close button. While an insert is in flight they ask first: closing then ...
void setPasswordVisible(bool show)
Show or mask the password field.
QHash< QString, QStringList > m_availableTemplates
QString m_file
Entry path relative to the store, without .gpg; empty for a new entry until accept() resolves the typ...
bool m_saving
True from accept() starting an insert until the backend reports back.
QShortcut * m_templateShortcut
Ctrl+T, created once templates are available; owned by the dialog.
void setEditorEnabled(bool enabled)
Enabled or grey out every editable field of the dialog.
void onShowError(int exitCode, const QString &err)
Handle a process error while waiting for an entry's decrypt.
void removeField(QLineEdit *line)
Drop a key: value field and its row from the form. The widgets are deleted once control is back in th...
QString m_storeRoot
Absolute store root while a new entry is being named; empty otherwise.
void setPass(const QString &output, const QString &file=QString())
Populate the dialog from a decrypted entry (Pass::finishedShow).
void copied(const QString &text)
Text was copied out of the password, a field or the body, marked as a secret: for ClipboardManager::t...
void setNewEntryLocation(const QString &storeRoot, const QStringList &folders, const QString &currentFolder)
Let a new entry be named inside the dialog: a folder picker over the store's folders and a name field...
void renameField(QLineEdit *line, FieldLabel *label, const QString &to)
Give a key: value field a new key (#132). Refused, with the reason in the status label,...
auto isOwnInsertReport() -> bool
Whether the insert report now arriving is this dialog's own.
PasswordConfiguration m_passConfig
Generator settings: character sets and default length.
auto resolveNewEntry(QString *problem) const -> QString
The name the user typed, resolved against the picked folder.
void usePwgen(bool usePwgen)
Enable or disable pwgen-style password generation mode.
void setPasswordCharTemplate(int templateIndex)
Set the password character template index.
void setTemplate(const QString &rawFields, bool useTemplate)
Set the template fields and whether templating is enabled.
void templateAll(bool templateAll)
Whether every key: value line becomes a field of its own.
void reportCopies(SecretLineEdit *line)
Forwards the line edit's SecretLineEdit::copied to this dialog's copied(), so every copy out of any f...
auto getPassword() -> QString
Retrieve the current text from the dialog's password field.
void markOtpFieldEdited()
Remember, on the line edit that sent textEdited(), that the user typed in it: only such a field has a...
void on_rejected()
Connected to QDialog::rejected: blanks the password and field widgets so the decrypted secret does no...
void onInsertFinished()
The insert started by accept() succeeded: close as accepted.
QList< QLineEdit * > m_templateLines
QPointer< QLineEdit > m_otpLine
void applyTemplate(const QString &templateName)
Switch to a named template: records it, selects it in the combo box and rebuilds the field rows throu...
void on_createPasswordButton_clicked()
"Generate" button: asks the backend for a password of the chosen length from the selected character s...
QString m_currentTemplateName
Name of the template currently applied; cycleTemplate() steps from it.
QPointer< QAction > m_otpWarning
A QLineEdit for a password that can be shown: whatever is copied out of it is marked as a secret and ...
Plain value-object holding all flat QtPass configuration.
Definition appsettings.h:36
Holds the password generator settings: which character set is selected, the alphabet of every set,...