QtPass 2.0.0
Developer documentation
Loading...
Searching...
No Matches
configdialog.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2014 Anne Jan Brouwer
2// SPDX-License-Identifier: GPL-3.0-or-later
8#ifndef SRC_CONFIGDIALOG_H_
9#define SRC_CONFIGDIALOG_H_
10
11#include "appsettings.h"
12#include "enums.h"
14#include "profile.h"
15
16#include <QDialog>
17#include <QHash>
18#include <QProcessEnvironment>
19#include <QSet>
20#include <optional>
21
22namespace Ui {
23class ConfigDialog;
24} // namespace Ui
25
26class QLabel;
27
37class ConfigDialog : public QDialog {
38 Q_OBJECT
39
40public:
45 explicit ConfigDialog(QWidget *parent);
46 ~ConfigDialog() override;
47
54 static auto isFingerprintList(const QString &setting) -> bool;
55
60 void useSelection(bool useSelection);
61
66 auto getProfiles() -> Profiles;
67
72 void useTrayIcon(bool useSystray);
73
78 void useGit(bool useGit);
79
84 void useOtp(bool useOtp);
85
91
96 void useQrencode(bool useQrencode);
97
102 void setPwgenPath(const QString &path);
103
108 void usePwgen(bool usePwgen);
109
115
121
122protected:
128 void changeEvent(QEvent *event) override;
129
130private slots:
136 void on_accepted();
170 void on_comboBoxClipboard_activated(int index);
207 void onProfileSelected(int row);
213 void onProfileNameEdited(const QString &name);
219 void onProfilePathEdited(const QString &path);
225 void onProfileSigningKeyEdited(const QString &key);
231 void onProfileGitToggled();
232
233private:
244 QString name;
249 };
250
252 QString name;
253 QString path;
254 QString key;
257 QString sharedKey;
262 [[nodiscard]] auto none() const -> bool {
263 return name.isEmpty() && path.isEmpty() && key.isEmpty();
264 }
265
269 [[nodiscard]] auto first() const -> QString {
270 return !name.isEmpty() ? name : !path.isEmpty() ? path : key;
271 }
272 };
273
275 QString m_nameTip;
278 QString m_pathTip;
281 QString m_keyTip;
283 QLabel *m_sharedKeyWarning = nullptr;
285 QLabel *m_passGitWarning = nullptr;
291 mutable QHash<QString, QString> m_primaryOf;
294 bool m_recheckSigners = false;
297 mutable std::optional<AppSettings> m_gpgSettings;
299 QList<ProfileEntry> m_entries;
304 bool m_loadingForm = false;
305
313 void loadProfileForm(int row);
318 auto currentEntry() -> ProfileEntry *;
324 void updateProfileStatus();
326 QScopedPointer<Ui::ConfigDialog> ui;
327
333 void setGitPath(const QString &path);
341 void setProfiles(Profiles profiles, const QString &currentProfile);
347 void usePass(bool usePass);
348
359 void applySettings(const AppSettings &settings);
368 auto readSettings() -> AppSettings;
369
375 void setGroupBoxState();
381 void updatePwgenCheckbox();
387 void updateGitCheckbox();
392 auto selectExecutable() -> QString;
397 auto selectFolder() -> QString;
404 void criticalMessage(const QString &title, const QString &text);
405
413 auto isQrencodeAvailable(const QString &configuredPath) -> bool;
419 void validate();
430 auto problemsOf(const ProfileEntry &entry,
431 const QHash<QString, int> &names) const -> ProfileProblems;
438 void showProblems(int row, const ProfileProblems &problems);
442 QStringList stores;
443 QList<QSet<QString>> keys;
444 };
445
449 [[nodiscard]] auto signingStores() const -> SigningStores;
458 [[nodiscard]] auto signerKeys(const QString &signingKey,
459 const QProcessEnvironment &env) const
460 -> QSet<QString>;
468 [[nodiscard]] auto sharingTheKey(int row, const SigningStores &resolved) const
469 -> QStringList;
470
477 void initializeNewProfiles(const Profiles &existingProfiles);
483 auto ensureProfileFolder(const QString &path) -> bool;
492 void initialiseProfileStore(const QString &name, const Profile &profile,
493 const QString &path);
503 void followActiveProfile(const Profiles &profiles);
504
508};
509
510#endif // SRC_CONFIGDIALOG_H_
AppSettings, the value object holding every flat QtPass setting.
void setPasswordConfiguration(const PasswordConfiguration &config)
Apply a password configuration to the dialog controls.
void on_deleteButton_clicked()
Remove the selected profile row (a message when none is); the list's currentRowChanged re-points the ...
std::optional< AppSettings > m_gpgSettings
void on_passwordCharTemplateSelector_activated(int index)
Show the chosen character set's characters in the line edit, editable only for the custom set.
static auto isFingerprintList(const QString &setting) -> bool
Whether a signing-key setting holds only full key fingerprints (40 or 64 hexadecimal characters each,...
void on_toolButtonGit_clicked()
Pick the git executable in a file dialog; a choice enables "useGit", a cancelled dialog keeps the fie...
auto sharingTheKey(int row, const SigningStores &resolved) const -> QStringList
The other profiles, for other stores, whose signing keys share a fingerprint with row row's.
void validate()
Check every profile (problemsOf(), sharingTheKey()), mark the rows and the form, enable OK only when ...
void updatePassGitWarning()
auto ensureProfileFolder(const QString &path) -> bool
Offer to create a new profile's store folder when it is missing.
void on_radioButtonNative_clicked()
Native (gpg/git) backend chosen: enable its group box, disable pass's.
QList< ProfileEntry > m_entries
The profiles as shown; index == row in profileList.
void useOtp(bool useOtp)
Enable or disable OTP support.
void updateSecretFieldsEnabled()
QString m_nameTip
bool m_gitOnBeforeEmptyPath
void loadProfileForm(int row)
Show row row's profile in the form (or clear and disable it for -1), with m_loadingForm set so the fi...
void on_pushButtonGenerateKey_clicked()
Open KeygenDialog for the gpg shown in the dialog.
void setPwgenPath(const QString &path)
Set the path to the pwgen executable.
void on_toolButtonStore_clicked()
Pick the password store folder for the pass backend's store path.
void updateGitCheckbox()
Make "use Git" follow the git path field: enabled with a path, turned off and disabled without one....
void on_checkBoxUseTrayIcon_clicked()
Hide-on-close and start-minimised are only offered with a tray icon.
QHash< QString, QString > m_primaryOf
void useGit(bool useGit)
Enable or disable git integration.
void on_radioButtonPass_clicked()
pass backend chosen: enable its group box, disable the native one.
void showProblems(int row, const ProfileProblems &problems)
Mark row row of the profile list, and the form fields when it is the row being edited,...
int m_currentEntry
Row whose fields the form shows, -1 for none.
void on_profilePathBrowse_clicked()
Pick the selected profile's store folder and store it in its entry.
QLabel * m_sharedKeyWarning
Below the signing key: the profiles that share it, if any.
QScopedPointer< Ui::ConfigDialog > ui
The widgets from configdialog.ui.
void on_checkBoxUsePwgen_clicked()
Enable pwgen's flags or the character-set controls, whichever the "use pwgen" box selects; nothing in...
auto signerKeys(const QString &signingKey, const QProcessEnvironment &env) const -> QSet< QString >
One profile's signing keys as signers: each key as written, plus the primary fingerprint gpg gives fo...
void setProfiles(Profiles profiles, const QString &currentProfile)
Fill the profile list and m_entries from profiles, dropping the empty-named leftover older versions w...
void useQrencode(bool useQrencode)
Enable or disable QR code display.
void on_autodetectButton_clicked()
Fill the pass, gpg (gpg2 first), git and pwgen paths from PATH, keeping a field as it is when nothing...
auto problemsOf(const ProfileEntry &entry, const QHash< QString, int > &names) const -> ProfileProblems
What is wrong with entry's name, store path and signing keys.
void on_comboBoxClipboard_activated(int index)
Enable the controls that only mean something with a clipboard (selection, hiding, autoclear) unless "...
void updatePwgenCheckbox()
Make "use pwgen" follow the pwgen path field: enabled with a path in native mode, unticked and disabl...
void onProfilePathEdited(const QString &path)
The path field was typed in: store it in the entry, validate and refresh the status line.
void usePass(bool usePass)
Tick the pass or the native radio button and enable the matching group box.
void useGrepSearch(bool useGrepSearch)
Enable or disable grep content search.
QLabel * m_passGitWarning
In the pass box: the stores pass would commit outside of, if any.
void initializeNewProfiles(const Profiles &existingProfiles)
For every saved profile whose store was not a profile's store when the dialog opened: offer to create...
ConfigDialog(QWidget *parent)
Construct a ConfigDialog associated with the given main window.
void onProfileSelected(int row)
The profile list's current row changed: show that profile.
auto signingStores() const -> SigningStores
Resolve every profile's store and fingerprints once.
auto selectExecutable() -> QString
Ask for an existing file in a read-only file dialog.
QString m_customPasswordChars
void setGitPath(const QString &path)
Show path as the git executable; an empty path disables and turns off "use Git".
void on_toolButtonPass_clicked()
Pick the pass executable in a file dialog; cancel keeps the field.
void setGroupBoxState()
Enable the group box of the chosen backend and, in pass mode, disable the password-generation control...
bool m_recheckSigners
void onProfileGitToggled()
One of the profile's Git boxes was clicked: all three flags become the profile's own (no longer follo...
void on_checkBoxUseGit_clicked()
Enable the Git-dependent boxes (add .gpg-id, auto pull/push, and in native mode the parent-repository...
auto getPasswordConfiguration() -> PasswordConfiguration
Read the current password configuration from the dialog controls.
auto currentEntry() -> ProfileEntry *
The entry the form is editing.
void initialiseProfileStore(const QString &name, const Profile &profile, const QString &path)
Ask for a new profile's recipients and initialise its store with them, keeping the active backend's s...
void criticalMessage(const QString &title, const QString &text)
QMessageBox::critical with a single OK button. Once a workaround for crashes in Qt 5....
void useTrayIcon(bool useSystray)
Show or hide the system tray icon.
void onProfileSigningKeyEdited(const QString &key)
The signing-key field was typed in: store it in the entry and validate (fingerprints only,...
void followActiveProfile(const Profiles &profiles)
Point the active profile at its new name after a rename (or at none after a deletion),...
void on_toolButtonGpg_clicked()
Pick the gpg executable in a file dialog; cancel keeps the field.
void warnAboutSshAuthSockOverride()
void applySettings(const AppSettings &settings)
Load the dialog's value widgets from an AppSettings struct.
auto getProfiles() -> Profiles
Return all configured profiles.
QString m_keyTip
void on_accepted()
On OK: warn about a dubious SSH_AUTH_SOCK override, save the settings and the profiles,...
void on_checkBoxSelection_clicked()
Re-apply the clipboard gating for the current clipboard mode.
void on_toolButtonPwgen_clicked()
Pick the pwgen executable; a choice enables "use pwgen", a cancelled dialog keeps the field and the c...
void usePwgen(bool usePwgen)
Enable or disable pwgen-based password generation.
QString m_pathTip
void changeEvent(QEvent *event) override
Forget the signing keys gpg did not know while the dialog is in the background, and check them again ...
void updateProfileStatus()
Refresh the status line under the form: the profile's name and cleaned path, marked "New" while the f...
auto isQrencodeAvailable(const QString &configuredPath) -> bool
Whether qrencode can run: configuredPath when it is an executable file, else a qrencode on Util's PAT...
auto readSettings() -> AppSettings
Build an AppSettings struct from the dialog's widgets.
void onProfileNameEdited(const QString &name)
The name field was typed in: store it in the entry and the list item, then validate (duplicates,...
void on_addButton_clicked()
Append a "New profile" row pointing at the global store path, select it and put the cursor in the nam...
auto selectFolder() -> QString
Ask for a directory in a directories-only file dialog.
void useSelection(bool useSelection)
Enable or disable clipboard selection mode.
The Enums namespace: clipboard behaviour and the identifiers of the subprocess kinds QtPass queues.
Value object for the password generator: chosen character set, its alphabets and the length.
One named password store (Profile) and the name-to-profile map (Profiles) the settings trade in.
QMap< QString, Profile > Profiles
All profiles by name. QMap so iteration order is the name order.
Definition profile.h:81
Plain value-object holding all flat QtPass configuration.
Definition appsettings.h:36
One row of the profile list while the dialog is open. A QList rather than the Profiles map so a profi...
QString name
The name as typed; may be empty or a duplicate.
QString originalName
Profile profile
What is wrong with one profile's fields; empty strings where nothing is.
QString name
Empty or duplicate name; empty when fine.
auto none() const -> bool
Whether all three fields are fine.
auto first() const -> QString
The first complaint, for a tooltip on the profile's row.
QString path
Missing store path; empty when fine.
QStringList stores
Canonical (or cleaned) store path.
QList< QSet< QString > > keys
Fingerprints of the signing key.
Holds the password generator settings: which character set is selected, the alphabet of every set,...
One named password store: where it is, how its .gpg-id is signed and, optionally, its own Git switche...
Definition profile.h:26