2121#include " ui_AddressItem.h"
2222
2323#include " CryptoDoc.h"
24- #include " DateTime.h"
2524#include " SslCertificate.h"
26- #include " Styles.h"
2725#include " dialogs/KeyDialog.h"
2826
2927using namespace ria ::qdigidoc4;
@@ -46,27 +44,23 @@ AddressItem::AddressItem(CKey k, QWidget *parent, bool showIcon)
4644 if (showIcon)
4745 ui->icon ->load (QStringLiteral (" :/images/icon_Krypto_small.svg" ));
4846 ui->icon ->setVisible (showIcon);
49- ui->name ->setFont (Styles::font (Styles::Regular, 14 , QFont::DemiBold));
50- ui->name ->installEventFilter (this );
51- ui->idType ->setFont (Styles::font (Styles::Regular, 11 ));
52- ui->idType ->installEventFilter (this );
47+ ui->name ->setAttribute (Qt::WA_TransparentForMouseEvents, true );
48+ ui->expire ->setAttribute (Qt::WA_TransparentForMouseEvents, true );
49+ ui->idType ->setAttribute (Qt::WA_TransparentForMouseEvents, true );
50+ if (!ui->key .unsupported )
51+ setCursor (Qt::PointingHandCursor);
5352
5453 connect (ui->add , &QToolButton::clicked, this , [this ]{ emit add (this );});
5554 connect (ui->remove , &QToolButton::clicked, this , [this ]{ emit remove (this );});
5655
57- ui->add ->setFont (Styles::font (Styles::Condensed, 12 ));
58- ui->added ->setFont (ui->add ->font ());
59-
60- ui->code = SslCertificate (ui->key .cert ).personalCode ().toHtmlEscaped ();
61- ui->label = (!ui->key .cert .subjectInfo (" GN" ).isEmpty () && !ui->key .cert .subjectInfo (" SN" ).isEmpty () ?
62- ui->key .cert .subjectInfo (" GN" ).join (' ' ) + " " + ui->key .cert .subjectInfo (" SN" ).join (' ' ) :
63- ui->key .cert .subjectInfo (" CN" ).join (' ' )).toHtmlEscaped ();
56+ ui->code = SslCertificate (ui->key .cert ).personalCode ();
57+ ui->label = !ui->key .cert .subjectInfo (" GN" ).isEmpty () && !ui->key .cert .subjectInfo (" SN" ).isEmpty () ?
58+ ui->key .cert .subjectInfo (" GN" ).join (' ' ) + ' ' + ui->key .cert .subjectInfo (" SN" ).join (' ' ) :
59+ ui->key .cert .subjectInfo (" CN" ).join (' ' );
6460 if (ui->label .isEmpty ())
65- ui->label = ui->key .recipient . toHtmlEscaped ( );
61+ ui->label = ui->key .fromKeyLabel (). value ( QStringLiteral ( " cn " ), ui-> key . recipient );
6662 setIdType ();
6763 showButton (AddressItem::Remove);
68- if (ui->key .unsupported )
69- ui->idType ->setText (tr (" Unsupported cryptographic algorithm or recipient type" ));
7064}
7165
7266AddressItem::~AddressItem ()
@@ -85,37 +79,24 @@ void AddressItem::changeEvent(QEvent* event)
8579 QWidget::changeEvent (event);
8680}
8781
88- bool AddressItem::eventFilter (QObject *o, QEvent *e)
89- {
90- if ((o == ui->name || o == ui->idType ) && e->type () == QEvent::MouseButtonRelease)
91- {
92- (new KeyDialog (ui->key , this ))->open ();
93- return true ;
94- }
95- return Item::eventFilter (o, e);
96- }
97-
9882const CKey& AddressItem::getKey () const
9983{
10084 return ui->key ;
10185}
10286
103- void AddressItem::idChanged (const CKey &key )
87+ void AddressItem::idChanged (const SslCertificate &cert )
10488{
89+ CKey key (cert);
10590 ui->yourself = !key.key .isNull () && ui->key == key;
10691 setName ();
10792}
10893
109- void AddressItem::idChanged (const SslCertificate &cert)
110- {
111- idChanged (CKey (cert));
112- }
113-
11494void AddressItem::initTabOrder (QWidget *item)
11595{
11696 setTabOrder (item, ui->name );
11797 setTabOrder (ui->name , ui->idType );
118- setTabOrder (ui->idType , ui->remove );
98+ setTabOrder (ui->idType , ui->expire );
99+ setTabOrder (ui->expire , ui->remove );
119100 setTabOrder (ui->remove , ui->added );
120101 setTabOrder (ui->added , lastTabWidget ());
121102}
@@ -127,13 +108,14 @@ QWidget* AddressItem::lastTabWidget()
127108
128109void AddressItem::mouseReleaseEvent (QMouseEvent * /* event*/ )
129110{
130- (new KeyDialog (ui->key , this ))->open ();
111+ if (!ui->key .unsupported )
112+ (new KeyDialog (ui->key , this ))->open ();
131113}
132114
133115void AddressItem::setName ()
134116{
135117 ui->name ->setText (QStringLiteral (" %1 <span style=\" font-weight:normal;\" >%2</span>" )
136- .arg (ui->label , ui->yourself ? ui->code + tr (" (Yourself)" ) : ui->code ));
118+ .arg (ui->label . toHtmlEscaped (), ( ui->yourself ? ui->code + tr (" (Yourself)" ) : ui->code ). toHtmlEscaped () ));
137119 if (ui->name ->text ().isEmpty ())
138120 ui->name ->hide ();
139121}
@@ -152,33 +134,53 @@ void AddressItem::stateChange(ContainerState state)
152134
153135void AddressItem::setIdType ()
154136{
155- ui->idType ->setHidden (ui->key .cert .isNull ());
156- if (ui->key .cert .isNull ())
157- return ;
158-
159- QString str;
137+ ui->expire ->clear ();
160138 SslCertificate cert (ui->key .cert );
161139 SslCertificate::CertType type = cert.type ();
162- if (type & SslCertificate::DigiIDType)
163- str = tr (" digi-ID" );
140+ if (ui->key .unsupported )
141+ {
142+ ui->label = tr (" Unsupported cryptographic algorithm or recipient type" );
143+ ui->idType ->clear ();
144+ }
145+ else if (type & SslCertificate::DigiIDType)
146+ ui->idType ->setText (tr (" digi-ID" ));
164147 else if (type & SslCertificate::EstEidType)
165- str = tr (" ID-card" );
148+ ui-> idType -> setText ( tr (" ID-card" ) );
166149 else if (type & SslCertificate::MobileIDType)
167- str = tr (" mobile-ID" );
150+ ui-> idType -> setText ( tr (" mobile-ID" ) );
168151 else if (type & SslCertificate::TempelType)
169152 {
170153 if (cert.keyUsage ().contains (SslCertificate::NonRepudiation))
171- str = tr (" e-Seal" );
154+ ui-> idType -> setText ( tr (" e-Seal" ) );
172155 else if (cert.enhancedKeyUsage ().contains (SslCertificate::ClientAuth))
173- str = tr (" Authentication certificate" );
156+ ui-> idType -> setText ( tr (" Authentication certificate" ) );
174157 else
175- str = tr (" Certificate for Encryption" );
158+ ui->idType ->setText (tr (" Certificate for Encryption" ));
159+ }
160+ else
161+ {
162+ auto items = ui->key .fromKeyLabel ();
163+ void (QT_TR_NOOP (" ID-CARD" ));
164+ ui->idType ->setText (tr (items[QStringLiteral (" type" )].toUtf8 ().data ()));
165+ if (QString server_exp = items[QStringLiteral (" server_exp" )]; !server_exp.isEmpty ())
166+ {
167+ auto date = QDateTime::fromSecsSinceEpoch (server_exp.toLongLong (), Qt::UTC);
168+ bool canDecrypt = QDateTime::currentDateTimeUtc () < date;
169+ ui->expire ->setProperty (" label" , canDecrypt ? QStringLiteral (" good" ) : QStringLiteral (" error" ));
170+ ui->expire ->setText (canDecrypt ? QStringLiteral (" %1 %2" ).arg (
171+ tr (" Decryption is possible until:" ), date.toLocalTime ().toString (QStringLiteral (" dd.MM.yyyy" ))) :
172+ tr (" Decryption has expired" ));
173+ }
174+ }
175+
176+ if (!cert.isNull ())
177+ {
178+ ui->expire ->setProperty (" label" , QStringLiteral (" default" ));
179+ ui->expire ->setText (QStringLiteral (" %1 %2" ).arg (
180+ cert.isValid () ? tr (" Expires on" ) : tr (" Expired on" ),
181+ cert.expiryDate ().toLocalTime ().toString (QStringLiteral (" dd.MM.yyyy" ))));
176182 }
177183
178- if (!str.isEmpty ())
179- str += QStringLiteral (" - " );
180- DateTime date (cert.expiryDate ().toLocalTime ());
181- ui->idType ->setText (QStringLiteral (" %1%2 %3" ).arg (str,
182- cert.isValid () ? tr (" Expires on" ) : tr (" Expired on" ),
183- date.formatDate (QStringLiteral (" dd. MMMM yyyy" ))));
184+ ui->idType ->setHidden (ui->idType ->text ().isEmpty ());
185+ ui->expire ->setHidden (ui->expire ->text ().isEmpty ());
184186}
0 commit comments