2323#include " CryptoDoc.h"
2424#include " DateTime.h"
2525#include " SslCertificate.h"
26- #include " Styles.h"
2726#include " dialogs/KeyDialog.h"
2827
28+ #include < QUrlQuery>
29+
2930using namespace ria ::qdigidoc4;
3031
3132class AddressItem ::Private: public Ui::AddressItem
@@ -46,27 +47,23 @@ AddressItem::AddressItem(CKey k, QWidget *parent, bool showIcon)
4647 if (showIcon)
4748 ui->icon ->load (QStringLiteral (" :/images/icon_Krypto_small.svg" ));
4849 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 );
5350
5451 connect (ui->add , &QToolButton::clicked, this , [this ]{ emit add (this );});
5552 connect (ui->remove , &QToolButton::clicked, this , [this ]{ emit remove (this );});
5653
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 ();
54+ ui->code = SslCertificate (ui->key .cert ).personalCode ();
55+ ui->label = !ui->key .cert .subjectInfo (" GN" ).isEmpty () && !ui->key .cert .subjectInfo (" SN" ).isEmpty () ?
56+ ui->key .cert .subjectInfo (" GN" ).join (' ' ) + ' ' + ui->key .cert .subjectInfo (" SN" ).join (' ' ) :
57+ ui->key .cert .subjectInfo (" CN" ).join (' ' );
6458 if (ui->label .isEmpty ())
65- ui->label = ui->key .recipient .toHtmlEscaped ();
59+ {
60+ if (QUrlQuery q = ui->key .fromKeyLabel (); !q.isEmpty ())
61+ ui->label = q.queryItemValue (QStringLiteral (" cn" ), QUrl::FullyDecoded);
62+ else
63+ ui->label = ui->key .recipient ;
64+ }
6665 setIdType ();
6766 showButton (AddressItem::Remove);
68- if (ui->key .unsupported )
69- ui->idType ->setText (tr (" Unsupported cryptographic algorithm or recipient type" ));
7067}
7168
7269AddressItem::~AddressItem ()
@@ -85,37 +82,24 @@ void AddressItem::changeEvent(QEvent* event)
8582 QWidget::changeEvent (event);
8683}
8784
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-
9885const CKey& AddressItem::getKey () const
9986{
10087 return ui->key ;
10188}
10289
103- void AddressItem::idChanged (const CKey &key )
90+ void AddressItem::idChanged (const SslCertificate &cert )
10491{
92+ CKey key (cert);
10593 ui->yourself = !key.key .isNull () && ui->key == key;
10694 setName ();
10795}
10896
109- void AddressItem::idChanged (const SslCertificate &cert)
110- {
111- idChanged (CKey (cert));
112- }
113-
11497void AddressItem::initTabOrder (QWidget *item)
11598{
11699 setTabOrder (item, ui->name );
117100 setTabOrder (ui->name , ui->idType );
118- setTabOrder (ui->idType , ui->remove );
101+ setTabOrder (ui->idType , ui->expire );
102+ setTabOrder (ui->expire , ui->remove );
119103 setTabOrder (ui->remove , ui->added );
120104 setTabOrder (ui->added , lastTabWidget ());
121105}
@@ -127,13 +111,14 @@ QWidget* AddressItem::lastTabWidget()
127111
128112void AddressItem::mouseReleaseEvent (QMouseEvent * /* event*/ )
129113{
130- (new KeyDialog (ui->key , this ))->open ();
114+ if (!ui->key .unsupported )
115+ (new KeyDialog (ui->key , this ))->open ();
131116}
132117
133118void AddressItem::setName ()
134119{
135120 ui->name ->setText (QStringLiteral (" %1 <span style=\" font-weight:normal;\" >%2</span>" )
136- .arg (ui->label , ui->yourself ? ui->code + tr (" (Yourself)" ) : ui->code ));
121+ .arg (ui->label . toHtmlEscaped (), ( ui->yourself ? ui->code + tr (" (Yourself)" ) : ui->code ). toHtmlEscaped () ));
137122 if (ui->name ->text ().isEmpty ())
138123 ui->name ->hide ();
139124}
@@ -152,33 +137,53 @@ void AddressItem::stateChange(ContainerState state)
152137
153138void AddressItem::setIdType ()
154139{
155- ui->idType ->setHidden (ui->key .cert .isNull ());
156- if (ui->key .cert .isNull ())
157- return ;
158-
159- QString str;
140+ ui->expire ->clear ();
160141 SslCertificate cert (ui->key .cert );
161142 SslCertificate::CertType type = cert.type ();
162- if (type & SslCertificate::DigiIDType)
163- str = tr (" digi-ID" );
143+ if (ui->key .unsupported )
144+ {
145+ ui->label = tr (" Unsupported cryptographic algorithm or recipient type" );
146+ ui->idType ->clear ();
147+ }
148+ else if (type & SslCertificate::DigiIDType)
149+ ui->idType ->setText (tr (" digi-ID" ));
164150 else if (type & SslCertificate::EstEidType)
165- str = tr (" ID-card" );
151+ ui-> idType -> setText ( tr (" ID-card" ) );
166152 else if (type & SslCertificate::MobileIDType)
167- str = tr (" mobile-ID" );
153+ ui-> idType -> setText ( tr (" mobile-ID" ) );
168154 else if (type & SslCertificate::TempelType)
169155 {
170156 if (cert.keyUsage ().contains (SslCertificate::NonRepudiation))
171- str = tr (" e-Seal" );
157+ ui-> idType -> setText ( tr (" e-Seal" ) );
172158 else if (cert.enhancedKeyUsage ().contains (SslCertificate::ClientAuth))
173- str = tr (" Authentication certificate" );
159+ ui-> idType -> setText ( tr (" Authentication certificate" ) );
174160 else
175- str = tr (" Certificate for Encryption" );
161+ ui->idType ->setText (tr (" Certificate for Encryption" ));
162+ }
163+ else
164+ {
165+ QUrlQuery q = ui->key .fromKeyLabel ();
166+ void (QT_TR_NOOP (" ID-CARD" ));
167+ ui->idType ->setText (tr (q.queryItemValue (QStringLiteral (" type" ), QUrl::FullyDecoded).toUtf8 ().data ()));
168+ if (QString server_exp = q.queryItemValue (QStringLiteral (" server_exp" ), QUrl::FullyDecoded); !server_exp.isEmpty ())
169+ {
170+ auto date = QDateTime::fromSecsSinceEpoch (server_exp.toLongLong ());
171+ bool canDecrypt = QDateTime::currentDateTimeUtc () < date;
172+ ui->expire ->setProperty (" label" , canDecrypt ? QStringLiteral (" good" ) : QStringLiteral (" error" ));
173+ ui->expire ->setText (canDecrypt ? QStringLiteral (" %1 %2" ).arg (
174+ tr (" Decryption is possible until:" ), DateTime (date.toLocalTime ()).formatDate (QStringLiteral (" dd. MMMM yyyy" ))) :
175+ tr (" Decryption has expired" ));
176+ }
177+ }
178+
179+ if (!cert.isNull ())
180+ {
181+ ui->expire ->setProperty (" label" , QStringLiteral (" default" ));
182+ ui->expire ->setText (QStringLiteral (" %1 %2" ).arg (
183+ cert.isValid () ? tr (" Expires on" ) : tr (" Expired on" ),
184+ DateTime (cert.expiryDate ().toLocalTime ()).formatDate (QStringLiteral (" dd. MMMM yyyy" ))));
176185 }
177186
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" ))));
187+ ui->idType ->setHidden (ui->idType ->text ().isEmpty ());
188+ ui->expire ->setHidden (ui->expire ->text ().isEmpty ());
184189}
0 commit comments