5#include "ui_usersdialog.h"
9#include <QRegularExpression>
21 : QDialog(parent), ui(new
Ui::
UsersDialog), m_dir(std::move(dir)) {
26 if (users.isEmpty()) {
27 QMessageBox::critical(parent, tr(
"Keylist missing"),
28 tr(
"Could not fetch list of available GPG keys"));
33 foreach (
const UserInfo &sec, secret_keys) {
34 for (
auto &user : users) {
35 if (sec.
key_id == user.key_id) {
36 user.have_secret =
true;
41 QList<UserInfo> selected_users;
45 m_dir.isEmpty() ?
"" : m_dir,
" ", &count);
46 if (!recipients.isEmpty()) {
49 foreach (
const UserInfo &sel, selected_users) {
50 for (
auto &user : users) {
51 if (sel.
key_id == user.key_id) {
57 if (count > selected_users.size()) {
60 m_dir.isEmpty() ?
"" : m_dir);
61 foreach (
const QString recipient, recipients) {
66 i.
name =
" ?? " + tr(
"Key not found in keyring");
75 connect(ui->buttonBox, &QDialogButtonBox::accepted,
this,
77 connect(ui->buttonBox, &QDialogButtonBox::rejected,
this, &QDialog::reject);
78 connect(ui->listWidget, &QListWidget::itemChanged,
this,
79 &UsersDialog::itemChange);
81 ui->lineEdit->setClearButtonEnabled(
true);
116 switch (event->key()) {
118 ui->lineEdit->clear();
129void UsersDialog::itemChange(QListWidgetItem *item) {
133 auto *info = item->data(Qt::UserRole).value<
UserInfo *>();
137 info->
enabled = item->checkState() == Qt::Checked;
145void UsersDialog::populateList(
const QString &filter) {
146 QRegularExpression nameFilter(
147 QRegularExpression::wildcardToRegularExpression(
"*" + filter +
"*"),
148 QRegularExpression::CaseInsensitiveOption);
149 ui->listWidget->clear();
150 if (!m_userList.isEmpty()) {
151 for (
auto &user : m_userList) {
152 if (filter.isEmpty() || nameFilter.match(user.name).hasMatch()) {
153 if (!user.isValid() && !ui->checkBox->isChecked()) {
156 if (user.expiry.toSecsSinceEpoch() > 0 &&
157 user.expiry.daysTo(QDateTime::currentDateTime()) > 0 &&
158 !ui->checkBox->isChecked()) {
161 QString userText = user.name +
"\n" + user.key_id;
162 if (user.created.toSecsSinceEpoch() > 0) {
164 " " + tr(
"created") +
" " +
165 QLocale::system().toString(user.created, QLocale::ShortFormat);
167 if (user.expiry.toSecsSinceEpoch() > 0) {
169 " " + tr(
"expires") +
" " +
170 QLocale::system().toString(user.expiry, QLocale::ShortFormat);
172 auto *item =
new QListWidgetItem(userText, ui->listWidget);
173 item->setCheckState(user.enabled ? Qt::Checked : Qt::Unchecked);
174 item->setData(Qt::UserRole, QVariant::fromValue(&user));
175 if (user.have_secret) {
177 item->setForeground(Qt::blue);
179 font.setFamily(font.defaultFamily());
182 }
else if (!user.isValid()) {
183 item->setBackground(QColor(164, 0, 0));
184 item->setForeground(Qt::white);
185 }
else if (user.expiry.toSecsSinceEpoch() > 0 &&
186 user.expiry.daysTo(QDateTime::currentDateTime()) > 0) {
187 item->setForeground(QColor(164, 0, 0));
188 }
else if (!user.fullyValid()) {
189 item->setBackground(QColor(164, 80, 0));
190 item->setForeground(Qt::white);
193 ui->listWidget->addItem(item);
203void UsersDialog::on_lineEdit_textChanged(
const QString &filter) {
204 populateList(filter);
210void UsersDialog::on_checkBox_clicked() { populateList(ui->lineEdit->text()); }
static auto getPass() -> Pass *
Handles listing and editing of GPG users.
~UsersDialog()
UsersDialog::~UsersDialog basic destructor.
void accept()
UsersDialog::accept.
UsersDialog(QString dir, QWidget *parent=nullptr)
UsersDialog::UsersDialog basic constructor.
void closeEvent(QCloseEvent *event)
UsersDialog::closeEvent might have to store size and location if that is wanted.
void keyPressEvent(QKeyEvent *event)
UsersDialog::keyPressEvent clear the lineEdit when escape is pressed. No action for Enter currently.
Stores key info lines including validity, creation date and more.
bool enabled
UserInfo::enabled.
QString key_id
UserInfo::key_id hexadecimal representation.
QString name
UserInfo::name full name.