QtPass  1.2.3
Multi-platform GUI for pass, the standard unix password manager.
usersdialog.cpp
Go to the documentation of this file.
1 #include "usersdialog.h"
2 #include "debughelper.h"
3 #include "ui_usersdialog.h"
4 #include <QCloseEvent>
5 #include <QRegExp>
6 #include <QWidget>
7 
12 UsersDialog::UsersDialog(QWidget *parent)
13  : QDialog(parent), ui(new Ui::UsersDialog) {
14  ui->setupUi(this);
15  connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
16  connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
17  connect(ui->listWidget, SIGNAL(itemChanged(QListWidgetItem *)), this,
18  SLOT(itemChange(QListWidgetItem *)));
19  userList = NULL;
20 
21 #if QT_VERSION >= 0x050200
22  ui->lineEdit->setClearButtonEnabled(true);
23 #endif
24 }
25 
29 UsersDialog::~UsersDialog() { delete ui; }
30 
31 Q_DECLARE_METATYPE(UserInfo *)
32 
33 
37 void UsersDialog::itemChange(QListWidgetItem *item) {
38  if (!item)
39  return;
40  UserInfo *info = item->data(Qt::UserRole).value<UserInfo *>();
41  if (!info)
42  return;
43  info->enabled = item->checkState() == Qt::Checked;
44 }
45 
50 void UsersDialog::setUsers(QList<UserInfo> *users) {
51  userList = users;
52  populateList("");
53 }
54 
60 void UsersDialog::populateList(const QString &filter) {
61  QRegExp nameFilter("*" + filter + "*");
62  nameFilter.setPatternSyntax(QRegExp::Wildcard);
63  nameFilter.setCaseSensitivity(Qt::CaseInsensitive);
64  ui->listWidget->clear();
65  if (userList) {
66  for (QList<UserInfo>::iterator it = userList->begin();
67  it != userList->end(); ++it) {
68  UserInfo &user(*it);
69  if (filter.isEmpty() || nameFilter.exactMatch(user.name)) {
70  if (!user.isValid() && !ui->checkBox->isChecked())
71  continue;
72  if (user.expiry.toTime_t() > 0 &&
73  user.expiry.daysTo(QDateTime::currentDateTime()) > 0 &&
74  !ui->checkBox->isChecked())
75  continue;
76  QString userText = user.name + "\n" + user.key_id;
77  if (user.created.toTime_t() > 0) {
78  userText += " " + tr("created") + " " +
79  user.created.toString(Qt::SystemLocaleShortDate);
80  }
81  if (user.expiry.toTime_t() > 0)
82  userText += " " + tr("expires") + " " +
83  user.expiry.toString(Qt::SystemLocaleShortDate);
84  QListWidgetItem *item = new QListWidgetItem(userText, ui->listWidget);
85  item->setCheckState(user.enabled ? Qt::Checked : Qt::Unchecked);
86  item->setData(Qt::UserRole, QVariant::fromValue(&user));
87  if (user.have_secret) {
88  // item->setForeground(QColor(32, 74, 135));
89  item->setForeground(Qt::blue);
90  QFont font;
91  font.setFamily(font.defaultFamily());
92  font.setBold(true);
93  item->setFont(font);
94  } else if (!user.isValid()) {
95  item->setBackground(QColor(164, 0, 0));
96  item->setForeground(Qt::white);
97  } else if (user.expiry.toTime_t() > 0 &&
98  user.expiry.daysTo(QDateTime::currentDateTime()) > 0) {
99  item->setForeground(QColor(164, 0, 0));
100  } else if (!user.fullyValid()) {
101  item->setBackground(QColor(164, 80, 0));
102  item->setForeground(Qt::white);
103  }
104 
105  ui->listWidget->addItem(item);
106  }
107  }
108  }
109 }
110 
115 void UsersDialog::on_lineEdit_textChanged(const QString &filter) {
116  populateList(filter);
117 }
118 
124 void UsersDialog::closeEvent(QCloseEvent *event) {
125  // TODO(annejan) save window size or somethign
126  event->accept();
127 }
128 
132 void UsersDialog::on_checkBox_clicked() { populateList(ui->lineEdit->text()); }
133 
139 void UsersDialog::keyPressEvent(QKeyEvent *event) {
140  switch (event->key()) {
141  case Qt::Key_Escape:
142  ui->lineEdit->clear();
143  break;
144  default:
145  break;
146  }
147 }
bool enabled
UserInfo::enabled.
Definition: userinfo.h:50
Definition: configdialog.h:9
void closeEvent(QCloseEvent *event)
UsersDialog::closeEvent might have to store size and location if that is wanted.
UsersDialog(QWidget *parent=0)
UsersDialog::UsersDialog basic constructor.
Definition: usersdialog.cpp:12
void setUsers(QList< UserInfo > *)
UsersDialog::setUsers update all the users.
Definition: usersdialog.cpp:50
Handles listing and editing of GPG users.
Definition: usersdialog.h:22
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.
Definition: userinfo.h:11
~UsersDialog()
UsersDialog::~UsersDialog basic destructor.
Definition: usersdialog.cpp:29