QtPass 2.0.0
Developer documentation
Loading...
Searching...
No Matches
usersdialog.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2015 Anne Jan Brouwer
2// SPDX-License-Identifier: GPL-3.0-or-later
7#ifndef SRC_USERSDIALOG_H_
8#define SRC_USERSDIALOG_H_
9
10#include "appsettings.h"
11#include "userinfo.h"
12
13#include <QDialog>
14#include <QList>
15#include <QRegularExpression>
16#include <QScopedPointer>
17#include <QSet>
18
19namespace Ui {
20class UsersDialog;
21}
22
23class Pass;
24class QKeyEvent;
25class QListWidgetItem;
26
36class UsersDialog : public QDialog {
37 Q_OBJECT
38
39public:
41 enum class Preselect {
42 FromList,
43 Nothing,
44 };
45
53 explicit UsersDialog(Pass *pass, const AppSettings &s, QString dir,
54 QWidget *parent = nullptr);
63 UsersDialog(Pass *pass, const AppSettings &s, QString dir,
64 Preselect preselect, QWidget *parent = nullptr);
68 ~UsersDialog() override;
69
78 void setInitOnAccept(bool initOnAccept) { m_initOnAccept = initOnAccept; }
79
84 [[nodiscard]] auto selectedUsers() const -> QList<UserInfo> {
85 return m_userList;
86 }
87
92 [[nodiscard]] auto hasSelection() const -> bool;
93
94public slots:
98 void accept() override;
99
100protected:
105 void keyPressEvent(QKeyEvent *event) override;
106
107private slots:
112 void itemChange(QListWidgetItem *item);
117 void on_lineEdit_textChanged(const QString &filter);
121 void on_checkBox_clicked();
132 void selectImportedKey(const QString &importedKey);
133
134private:
136 QScopedPointer<Ui::UsersDialog> ui;
138 QString m_passStore;
139 QString m_gpgExe;
141 bool m_initOnAccept{true};
143 void updateOkButton();
144 QString m_dir;
148 bool m_listRead = false;
152 int m_readState = 0;
154 QStringList m_readRecipients;
155 QString m_lastFilter;
161 QSet<QString> m_notLookedUp;
163 QRegularExpression m_cachedNameFilter;
164 mutable QDateTime m_cachedCurrentDateTime;
167 false;
168
171 void restoreDialogState();
172
176 void connectSignals();
177
182 auto loadGpgKeys() -> bool;
183
188 void markSecretKeys(QList<UserInfo> &users);
189
193 void loadRecipients();
194
201 [[nodiscard]] auto listChangedSinceRead() const -> bool;
209 const QString &text,
210 const QString &name = QStringLiteral("recipientWarning"));
217 void showNestedLists();
225 void selectRecipients(const QStringList &listed);
232 void keepAsWritten(const QString &line, const QString &why);
241 auto tickReached(const QStringList &ids, const QStringList &lines) -> bool;
249 auto setAsideHeldTwice(QStringList *recipients) -> bool;
258 auto probeEachLine(QStringList *recipients) -> bool;
265 void searchKeyring(const QStringList &recipients);
266
271 void populateList(const QString &filter = QString());
279 bool passesFilter(const UserInfo &user, const QString &filter,
280 const QRegularExpression &nameFilter) const;
286 auto isUserExpired(const UserInfo &user) const -> bool;
293 QString buildUserText(const UserInfo &user) const;
299 void applyUserStyling(QListWidgetItem *item, const UserInfo &user) const;
300};
301
302#endif // SRC_USERSDIALOG_H_
AppSettings, the value object holding every flat QtPass setting.
Abstract base class for password store operations.
Definition pass.h:77
QString m_cachedPatternString
~UsersDialog() override
Destroys the dialog and its generated form.
void updateOkButton()
Enable OK only while at least one key is ticked (hasSelection()).
bool m_initOnAccept
void itemChange(QListWidgetItem *item)
Handle user selection change.
QRegularExpression m_cachedNameFilter
void on_importKeyButton_clicked()
Import a GPG key and refresh the list.
auto selectedUsers() const -> QList< UserInfo >
The key list with the user's choice in each entry's enabled flag.
Definition usersdialog.h:84
void on_lineEdit_textChanged(const QString &filter)
Filter user list.
auto isUserExpired(const UserInfo &user) const -> bool
Check if GPG key is expired.
void keyPressEvent(QKeyEvent *event) override
Handle key press.
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 selectRecipients(const QStringList &listed)
Tick the keys the folder is encrypted to, and list recipients no key in the keyring answers to,...
void applyUserStyling(QListWidgetItem *item, const UserInfo &user) const
Apply visual styling to user item.
void searchKeyring(const QStringList &recipients)
Tick the keys a keyring search resolves recipients to, and list the lines no key answers to,...
QString m_dir
Preselect
Whether the recipients on disk are ticked when it opens.
Definition usersdialog.h:41
@ FromList
The folder's recipient list, as the backend reads it.
Definition usersdialog.h:42
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 s...
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.
QString m_lastFilter
QList< UserInfo > m_userList
void connectSignals()
Connect dialog signals.
auto setAsideHeldTwice(QStringList *recipients) -> bool
Keep as written, and warn about, the lines a key ID or fingerprint names that two key blocks hold,...
QString m_passStore
QDateTime m_cachedCurrentDateTime
void restoreDialogState()
auto listChangedSinceRead() const -> bool
Whether the folder's recipient list reads differently now from when loadRecipients() read it: a pull,...
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 r...
QStringList m_readRecipients
The recipients the list named when the dialog read it.
void populateList(const QString &filter=QString())
Populate user 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...
void showNestedLists()
Name the folders below this one that have a recipient list of their own: saving here does not change ...
void loadRecipients()
Load recipients and handle missing keys.
void accept() override
Handle dialog acceptance.
bool m_cachedDateTimeValid
QString m_gpgExe
UsersDialog(Pass *pass, const AppSettings &s, QString dir, QWidget *parent=nullptr)
Construct users dialog.
void markSecretKeys(QList< UserInfo > &users)
Mark which keys have secret counterparts.
Preselect m_preselect
void setInitOnAccept(bool initOnAccept)
Choose whether OK runs Pass::Init on the folder.
Definition usersdialog.h:78
auto probeEachLine(QStringList *recipients) -> bool
After gpg refused the list as a whole, probe each line on its own (address and name lines first,...
QSet< QString > m_notLookedUp
.gpg-id lines selectRecipients() listed unticked without asking gpg. They are shown without "Show unu...
bool passesFilter(const UserInfo &user, const QString &filter, const QRegularExpression &nameFilter) const
Check if user passes filter.
auto hasSelection() const -> bool
Whether at least one key is ticked.
void on_checkBox_clicked()
Handle select all checkbox.
QScopedPointer< Ui::UsersDialog > ui
The widgets from usersdialog.ui.
auto loadGpgKeys() -> bool
Load GPG keys and determine secret key status.
Pass * m_pass
Plain value-object holding all flat QtPass configuration.
Definition appsettings.h:36
Stores GPG key info including validity, creation date, and more.
Definition userinfo.h:20
UserInfo, one GPG key as listed by gpg, with the selection flag the recipient dialogs use.