Skip to content

Commit

Permalink
Cleanup code and event is handled (open-eid#1189)
Browse files Browse the repository at this point in the history
IB-7615

Signed-off-by: Raul Metsma <[email protected]>
  • Loading branch information
metsma authored May 19, 2023
1 parent 29b9f50 commit b08eff0
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 152 deletions.
6 changes: 3 additions & 3 deletions client/dialogs/AddRecipients.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ AddressItem * AddRecipients::addRecipientToLeftPane(const QSslCertificate& cert)
leftList.insert(cert, leftItem);
ui->leftPane->addWidget(leftItem);
bool contains = rightList.contains(cert);
leftItem->disable(contains);
leftItem->setDisabled(contains);
leftItem->showButton(contains ? AddressItem::Added : AddressItem::Add);

connect(leftItem, &AddressItem::add, this, [this](Item *item) {
Expand Down Expand Up @@ -258,7 +258,7 @@ bool AddRecipients::addRecipientToRightPane(const CKey &key, bool update)
void AddRecipients::addRecipientToRightPane(AddressItem *leftItem, bool update)
{
if(addRecipientToRightPane(leftItem->getKey(), update)) {
leftItem->disable(true);
leftItem->setDisabled(true);
leftItem->showButton(AddressItem::Added);
}
}
Expand Down Expand Up @@ -332,7 +332,7 @@ void AddRecipients::removeRecipientFromRightPane(Item *toRemove)
auto *rightItem = qobject_cast<AddressItem*>(toRemove);
if(auto it = leftList.find(rightItem->getKey().cert); it != leftList.end())
{
it.value()->disable(false);
it.value()->setDisabled(false);
it.value()->showButton(AddressItem::Add);
}
rightList.removeAll(rightItem->getKey().cert);
Expand Down
61 changes: 35 additions & 26 deletions client/widgets/AddressItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,28 @@
#include "AddressItem.h"
#include "ui_AddressItem.h"

#include "CryptoDoc.h"
#include "DateTime.h"
#include "SslCertificate.h"
#include "Styles.h"
#include "dialogs/KeyDialog.h"

using namespace ria::qdigidoc4;

class AddressItem::Private: public Ui::AddressItem
{
public:
QString code;
CKey key;
QString label;
bool yourself = false;
};

AddressItem::AddressItem(CKey k, QWidget *parent, bool showIcon)
: Item(parent)
, ui(new Ui::AddressItem)
, key(std::move(k))
, ui(new Private)
{
ui->key = std::move(k);
ui->setupUi(this);
if(showIcon)
ui->icon->load(QStringLiteral(":/images/icon_Krypto_small.svg"));
Expand All @@ -43,21 +53,19 @@ AddressItem::AddressItem(CKey k, QWidget *parent, bool showIcon)

ui->remove->setIcons(QStringLiteral("/images/icon_remove.svg"), QStringLiteral("/images/icon_remove_hover.svg"),
QStringLiteral("/images/icon_remove_pressed.svg"), 17, 17);
ui->remove->init(LabelButton::White, QString(), 0);
ui->remove->init(LabelButton::White, {}, 0);
connect(ui->add, &QToolButton::clicked, this, [this]{ emit add(this);});
connect(ui->remove, &LabelButton::clicked, this, [this]{ emit remove(this);});

ui->add->setFont(Styles::font(Styles::Condensed, 12));
ui->added->setFont(Styles::font(Styles::Condensed, 12));

ui->add->hide();
ui->added->hide();
ui->added->setDisabled(true);

code = SslCertificate(key.cert).personalCode().toHtmlEscaped();
name = (!key.cert.subjectInfo("GN").isEmpty() && !key.cert.subjectInfo("SN").isEmpty() ?
key.cert.subjectInfo("GN").join(' ') + " " + key.cert.subjectInfo("SN").join(' ') :
key.cert.subjectInfo("CN").join(' ')).toHtmlEscaped();
ui->added->setFont(ui->add->font());

ui->code = SslCertificate(ui->key.cert).personalCode().toHtmlEscaped();
ui->label = (!ui->key.cert.subjectInfo("GN").isEmpty() && !ui->key.cert.subjectInfo("SN").isEmpty() ?
ui->key.cert.subjectInfo("GN").join(' ') + " " + ui->key.cert.subjectInfo("SN").join(' ') :
ui->key.cert.subjectInfo("CN").join(' ')).toHtmlEscaped();
if(ui->label.isEmpty())
ui->label = ui->key.recipient;
setIdType();
showButton(AddressItem::Remove);
}
Expand All @@ -78,28 +86,24 @@ void AddressItem::changeEvent(QEvent* event)
QWidget::changeEvent(event);
}

void AddressItem::disable(bool disable)
{
setStyleSheet(QStringLiteral("border: solid rgba(217, 217, 216, 0.45); border-width: 0px 0px 1px 0px;"
"background-color: %1; color: #000000; text-decoration: none solid rgb(0, 0, 0);")
.arg(disable ? QStringLiteral("#F0F0F0") : QStringLiteral("#FFFFFF")));
}

bool AddressItem::eventFilter(QObject *o, QEvent *e)
{
if((o == ui->name || o == ui->idType) && e->type() == QEvent::MouseButtonRelease)
(new KeyDialog(key, this))->open();
{
(new KeyDialog(ui->key, this))->open();
return true;
}
return Item::eventFilter(o, e);
}

const CKey& AddressItem::getKey() const
{
return key;
return ui->key;
}

void AddressItem::idChanged(const SslCertificate &cert)
{
yourself = !cert.isNull() && key.cert == cert;
ui->yourself = !cert.isNull() && ui->key.cert == cert;
setName();
}

Expand All @@ -119,12 +123,13 @@ QWidget* AddressItem::lastTabWidget()

void AddressItem::mouseReleaseEvent(QMouseEvent * /*event*/)
{
(new KeyDialog(key, this))->open();
(new KeyDialog(ui->key, this))->open();
}

void AddressItem::setName()
{
ui->name->setText(QStringLiteral("%1 <span style=\"font-weight:normal;\">%2</span>").arg(name, yourself ? code + tr(" (Yourself)") : code));
ui->name->setText(QStringLiteral("%1 <span style=\"font-weight:normal;\">%2</span>")
.arg(ui->label, ui->yourself ? ui->code + tr(" (Yourself)") : ui->code));
}

void AddressItem::showButton(ShowToolButton show)
Expand All @@ -141,8 +146,12 @@ void AddressItem::stateChange(ContainerState state)

void AddressItem::setIdType()
{
ui->idType->setHidden(ui->key.cert.isNull());
if(ui->key.cert.isNull())
return;

QString str;
SslCertificate cert(key.cert);
SslCertificate cert(ui->key.cert);
SslCertificate::CertType type = cert.type();
if(type & SslCertificate::DigiIDType)
str = tr("digi-ID");
Expand Down
19 changes: 5 additions & 14 deletions client/widgets/AddressItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@

#include "widgets/Item.h"

#include "CryptoDoc.h"

namespace Ui {
class AddressItem;
}
class CKey;

class AddressItem final : public Item
{
Expand All @@ -37,13 +33,12 @@ class AddressItem final : public Item
None,
Remove,
Add,
Added
Added,
};

explicit AddressItem(CKey k, QWidget *parent = nullptr, bool showIcon = false);
explicit AddressItem(CKey k, QWidget *parent = {}, bool showIcon = false);
~AddressItem() final;

void disable(bool disable);
const CKey& getKey() const;
void idChanged(const SslCertificate &cert) final;
void initTabOrder(QWidget *item) final;
Expand All @@ -58,10 +53,6 @@ class AddressItem final : public Item
void setName();
void setIdType();

Ui::AddressItem *ui;

QString code;
CKey key;
QString name;
bool yourself = false;
class Private;
Private *ui;
};
Loading

0 comments on commit b08eff0

Please sign in to comment.