QtPass  1.2.0-pre
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 <QRegExp>
5 
10 UsersDialog::UsersDialog(QWidget *parent)
11  : QDialog(parent), ui(new Ui::UsersDialog) {
12  ui->setupUi(this);
13  connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
14  connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
15  connect(ui->listWidget, SIGNAL(itemChanged(QListWidgetItem *)), this,
16  SLOT(itemChange(QListWidgetItem *)));
17  userList = NULL;
18 
19 #if QT_VERSION >= 0x050200
20  ui->lineEdit->setClearButtonEnabled(true);
21 #endif
22 }
23 
27 UsersDialog::~UsersDialog() { delete ui; }
28 
29 Q_DECLARE_METATYPE(UserInfo *)
30 
31 
35 void UsersDialog::itemChange(QListWidgetItem *item) {
36  if (!item)
37  return;
38  UserInfo *info = item->data(Qt::UserRole).value<UserInfo *>();
39  if (!info)
40  return;
41  info->enabled = item->checkState() == Qt::Checked;
42 }
43 
48 void UsersDialog::setUsers(QList<UserInfo> *users) {
49  userList = users;
50  populateList("");
51 }
52 
58 void UsersDialog::populateList(const QString &filter) {
59  QRegExp nameFilter("*" + filter + "*");
60  nameFilter.setPatternSyntax(QRegExp::Wildcard);
61  nameFilter.setCaseSensitivity(Qt::CaseInsensitive);
62  ui->listWidget->clear();
63  if (userList) {
64  for (QList<UserInfo>::iterator it = userList->begin();
65  it != userList->end(); ++it) {
66  UserInfo &user(*it);
67  if (filter.isEmpty() || nameFilter.exactMatch(user.name)) {
68  if (!user.isValid() && !ui->checkBox->isChecked())
69  continue;
70  if (user.expiry.toTime_t() > 0 &&
71  user.expiry.daysTo(QDateTime::currentDateTime()) > 0 &&
72  !ui->checkBox->isChecked())
73  continue;
74  QString userText = user.name + "\n" + user.key_id;
75  if (user.created.toTime_t() > 0) {
76  userText += " " + tr("created") + " " +
77  user.created.toString(Qt::SystemLocaleShortDate);
78  }
79  if (user.expiry.toTime_t() > 0)
80  userText += " " + tr("expires") + " " +
81  user.expiry.toString(Qt::SystemLocaleShortDate);
82  QListWidgetItem *item = new QListWidgetItem(userText, ui->listWidget);
83  item->setCheckState(user.enabled ? Qt::Checked : Qt::Unchecked);
84  item->setData(Qt::UserRole, QVariant::fromValue(&user));
85  if (user.have_secret) {
86  // item->setForeground(QColor(32, 74, 135));
87  item->setForeground(Qt::blue);
88  QFont font;
89  font.setFamily(font.defaultFamily());
90  font.setBold(true);
91  item->setFont(font);
92  } else if (!user.isValid()) {
93  item->setBackground(QColor(164, 0, 0));
94  item->setForeground(Qt::white);
95  } else if (user.expiry.toTime_t() > 0 &&
96  user.expiry.daysTo(QDateTime::currentDateTime()) > 0) {
97  item->setForeground(QColor(164, 0, 0));
98  } else if (!user.fullyValid()) {
99  item->setBackground(QColor(164, 80, 0));
100  item->setForeground(Qt::white);
101  }
102 
103  ui->listWidget->addItem(item);
104  }
105  }
106  }
107 }
108 
113 void UsersDialog::on_lineEdit_textChanged(const QString &filter) {
114  populateList(filter);
115 }
116 
122 void UsersDialog::closeEvent(QCloseEvent *event) {
123  // TODO(annejan) save window size or somethign
124  event->accept();
125 }
126 
130 void UsersDialog::on_checkBox_clicked() { populateList(ui->lineEdit->text()); }
131 
137 void UsersDialog::keyPressEvent(QKeyEvent *event) {
138  switch (event->key()) {
139  case Qt::Key_Escape:
140  ui->lineEdit->clear();
141  break;
142  default:
143  break;
144  }
145 }
QDateTime expiry
UserInfo::expiry date/time key expires.
Definition: datahelpers.h:89
QDateTime created
UserInfo::created date/time key was created.
Definition: datahelpers.h:93
bool enabled
UserInfo::enabled.
Definition: datahelpers.h:85
QString key_id
UserInfo::key_id hexadecimal representation.
Definition: datahelpers.h:71
bool have_secret
UserInfo::have_secret secret key is available (can decrypt with this key)
Definition: datahelpers.h:81
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:10
void setUsers(QList< UserInfo > *)
UsersDialog::setUsers update all the users.
Definition: usersdialog.cpp:48
Handles listing and editing of GPG users.
Definition: usersdialog.h:23
void keyPressEvent(QKeyEvent *event)
UsersDialog::keyPressEvent clear the lineEdit when escape is pressed. No action for Enter currently...
bool isValid()
UserInfo::isValid when fullyValid or marginallyValid.
Definition: datahelpers.h:62
QString name
UserInfo::name full name.
Definition: datahelpers.h:67
Stores key info lines including validity, creation date and more.
Definition: datahelpers.h:46
bool fullyValid()
UserInfo::fullyValid when validity is f or u. http://git.gnupg.org/cgi-bin/gitweb.cgi?p=gnupg.git;a=blob_plain;f=doc/DETAILS.
Definition: datahelpers.h:53
~UsersDialog()
UsersDialog::~UsersDialog basic destructor.
Definition: usersdialog.cpp:27