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
18namespace Ui {
19class UsersDialog;
20}
21
22class Pass;
23class QKeyEvent;
24class QListWidgetItem;
25
35class UsersDialog : public QDialog {
36 Q_OBJECT
37
38public:
40 enum class Preselect {
41 FromList,
42 Nothing,
43 };
44
52 explicit UsersDialog(Pass *pass, const AppSettings &s, QString dir,
53 QWidget *parent = nullptr);
62 UsersDialog(Pass *pass, const AppSettings &s, QString dir,
63 Preselect preselect, QWidget *parent = nullptr);
67 ~UsersDialog() override;
68
77 void setInitOnAccept(bool initOnAccept) { m_initOnAccept = initOnAccept; }
78
83 [[nodiscard]] auto selectedUsers() const -> QList<UserInfo> {
84 return m_userList;
85 }
86
91 [[nodiscard]] auto hasSelection() const -> bool;
92
93public slots:
97 void accept() override;
98
99protected:
104 void keyPressEvent(QKeyEvent *event) override;
105
106private slots:
111 void itemChange(QListWidgetItem *item);
116 void on_lineEdit_textChanged(const QString &filter);
120 void on_checkBox_clicked();
131 void selectImportedKey(const QString &importedKey);
132
133private:
135 QScopedPointer<Ui::UsersDialog> ui;
137 QString m_passStore;
138 QString m_gpgExe;
140 bool m_initOnAccept{true};
142 void updateOkButton();
143 QString m_dir;
145 QString m_lastFilter;
147 QRegularExpression m_cachedNameFilter;
148 mutable QDateTime m_cachedCurrentDateTime;
151 false;
152
155 void restoreDialogState();
156
160 void connectSignals();
161
166 auto loadGpgKeys() -> bool;
167
172 void markSecretKeys(QList<UserInfo> &users);
173
177 void loadRecipients();
183 void showRecipientWarning(const QString &text);
189 void selectRecipients(const QStringList &recipients);
190
195 void populateList(const QString &filter = QString());
203 bool passesFilter(const UserInfo &user, const QString &filter,
204 const QRegularExpression &nameFilter) const;
210 auto isUserExpired(const UserInfo &user) const -> bool;
216 QString buildUserText(const UserInfo &user) const;
222 void applyUserStyling(QListWidgetItem *item, const UserInfo &user) const;
223};
224
225#endif // SRC_USERSDIALOG_H_
AppSettings, the value object holding every flat QtPass setting.
Abstract base class for password store operations.
Definition pass.h:75
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:83
void on_lineEdit_textChanged(const QString &filter)
Filter user list.
void showRecipientWarning(const QString &text)
Show text above the key list in bold red, for a recipient list that could not be verified.
auto isUserExpired(const UserInfo &user) const -> bool
Check if GPG key is expired.
void keyPressEvent(QKeyEvent *event) override
Handle key press.
void applyUserStyling(QListWidgetItem *item, const UserInfo &user) const
Apply visual styling to user item.
QString m_dir
Preselect
Whether the recipients on disk are ticked when it opens.
Definition usersdialog.h:40
@ FromList
The folder's recipient list, as the backend reads it.
Definition usersdialog.h:41
QString m_lastFilter
QList< UserInfo > m_userList
void connectSignals()
Connect dialog signals.
QString m_passStore
QDateTime m_cachedCurrentDateTime
void restoreDialogState()
QString buildUserText(const UserInfo &user) const
Build display text for user.
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 selectRecipients(const QStringList &recipients)
Tick the keys the folder is encrypted to, and list recipients no key in the keyring answers to,...
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:77
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:19
UserInfo, one GPG key as listed by gpg, with the selection flag the recipient dialogs use.