3#include "ui_usersdialog.h"
7#include <QRegularExpression>
19 : QDialog(parent), ui(new
Ui::
UsersDialog), m_dir(std::move(dir)) {
24 if (users.isEmpty()) {
25 QMessageBox::critical(parent, tr(
"Keylist missing"),
26 tr(
"Could not fetch list of available GPG keys"));
31 foreach (
const UserInfo &sec, secret_keys) {
32 for (
auto &user : users)
33 if (sec.
key_id == user.key_id)
34 user.have_secret =
true;
37 QList<UserInfo> selected_users;
41 m_dir.isEmpty() ?
"" : m_dir,
" ", &count);
42 if (!recipients.isEmpty())
44 foreach (
const UserInfo &sel, selected_users) {
45 for (
auto &user : users)
46 if (sel.
key_id == user.key_id)
50 if (count > selected_users.size()) {
53 m_dir.isEmpty() ?
"" : m_dir);
54 foreach (
const QString recipient, recipients) {
59 i.
name =
" ?? " + tr(
"Key not found in keyring");
68 connect(ui->buttonBox, &QDialogButtonBox::accepted,
this,
70 connect(ui->buttonBox, &QDialogButtonBox::rejected,
this, &QDialog::reject);
71 connect(ui->listWidget, &QListWidget::itemChanged,
this,
72 &UsersDialog::itemChange);
74 ui->lineEdit->setClearButtonEnabled(
true);
109 switch (event->key()) {
111 ui->lineEdit->clear();
122void UsersDialog::itemChange(QListWidgetItem *item) {
125 auto *info = item->data(Qt::UserRole).value<
UserInfo *>();
128 info->
enabled = item->checkState() == Qt::Checked;
136void UsersDialog::populateList(
const QString &filter) {
137 QRegularExpression nameFilter(
138 QRegularExpression::wildcardToRegularExpression(
"*" + filter +
"*"),
139 QRegularExpression::CaseInsensitiveOption);
140 ui->listWidget->clear();
141 if (!m_userList.isEmpty()) {
142 for (
auto &user : m_userList) {
143 if (filter.isEmpty() || nameFilter.match(user.name).hasMatch()) {
144 if (!user.isValid() && !ui->checkBox->isChecked())
146 if (user.expiry.toSecsSinceEpoch() > 0 &&
147 user.expiry.daysTo(QDateTime::currentDateTime()) > 0 &&
148 !ui->checkBox->isChecked())
150 QString userText = user.name +
"\n" + user.key_id;
151 if (user.created.toSecsSinceEpoch() > 0) {
153 " " + tr(
"created") +
" " +
154 QLocale::system().toString(user.created, QLocale::ShortFormat);
156 if (user.expiry.toSecsSinceEpoch() > 0)
158 " " + tr(
"expires") +
" " +
159 QLocale::system().toString(user.expiry, QLocale::ShortFormat);
160 auto *item =
new QListWidgetItem(userText, ui->listWidget);
161 item->setCheckState(user.enabled ? Qt::Checked : Qt::Unchecked);
162 item->setData(Qt::UserRole, QVariant::fromValue(&user));
163 if (user.have_secret) {
165 item->setForeground(Qt::blue);
167 font.setFamily(font.defaultFamily());
170 }
else if (!user.isValid()) {
171 item->setBackground(QColor(164, 0, 0));
172 item->setForeground(Qt::white);
173 }
else if (user.expiry.toSecsSinceEpoch() > 0 &&
174 user.expiry.daysTo(QDateTime::currentDateTime()) > 0) {
175 item->setForeground(QColor(164, 0, 0));
176 }
else if (!user.fullyValid()) {
177 item->setBackground(QColor(164, 80, 0));
178 item->setForeground(Qt::white);
181 ui->listWidget->addItem(item);
191void UsersDialog::on_lineEdit_textChanged(
const QString &filter) {
192 populateList(filter);
198void UsersDialog::on_checkBox_clicked() { populateList(ui->lineEdit->text()); }
static QStringList getRecipientString(QString for_file, QString separator=" ", int *count=NULL)
Pass::getRecipientString formated string for use with GPG.
static QStringList getRecipientList(QString for_file)
Pass::getRecipientList return list of gpg-id's to encrypt for.
QList< UserInfo > listKeys(QStringList keystrings, bool secret=false)
Pass::listKeys list users.
virtual void Init(QString path, const QList< UserInfo > &users)=0
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.