/*! @file @id $Id$ */ // 1 2 3 4 5 6 7 8 // 45678901234567890123456789012345678901234567890123456789012345678901234567890 #ifndef __PINDIALOG_HXX__ #define __PINDIALOG_HXX__ #include #include #include #include #include #include #include namespace qbrowserlib { class PinEntry: public QDialog, public Ui::PinEntry { Q_OBJECT; public: PinEntry(const QSslCertificate& cert, QWidget *parent=0): QDialog(parent), _maxPinLen(-1), _minPinLen(0) { setModal(true); setupUi(this); _cert->certificate(cert); on__showDetails_toggled(false); _name->setText(utfConv(cert.subjectInfo(QSslCertificate::CommonName) #if QT_VERSION >= 0x050000 .join('\n') #endif ).remove(" (Authentication)")); #if QT_VERSION < 0x050000 _mail->setText(utfConv(cert.alternateSubjectNames() .value(QSsl::EmailEntry))); #else _mail->setText(utfConv(cert.subjectAlternativeNames() .value(QSsl::EmailEntry))); #endif if (!cert.subjectInfo(QByteArray("serialNumber")).isEmpty()) { _certSerialTitle->setText(tr("SuisseID Number:")); _certSerial->setText(cert.subjectInfo(QByteArray("serialNumber")) #if QT_VERSION >= 0x050000 .join('\n') #endif ); } else { _certSerialTitle->setText (tr("Postzertifikat:", "title for postzertificate serial number")); _certSerial->setText(cert.serialNumber()); } } PinEntry& tokeninfo(unsigned int min, unsigned int max) { _maxPinLen = max; _minPinLen = min; on__pin_textChanged(_pin->text()); return *this; } PinEntry& retries(int num) { _pinstatus->setCurrentIndex(num==-1?1:(num==-2?2:0)); _retries->setText(tr("there are %1 PIN attempts left").arg(num)); return *this; } QString pin() const { return _pin->text(); } int myexec() { TRC; _pin->clear(); show(); int res(_run.exec(QEventLoop::ExcludeSocketNotifiers)); hide(); return res; } public Q_SLOTS: virtual void accept() { TRC; QDialog::accept(); } virtual void done(int r) { TRC; LOG<setVisible(s); adjustSize(); } void on__pin_textChanged(const QString &text) { TRC; LOG<<"pin length - min: "<<_minPinLen<<" - max: "<<_maxPinLen; _buttonBox->button(QDialogButtonBox::Ok) ->setEnabled((unsigned long)text.size()>=_minPinLen && (unsigned long)text.size()<=_maxPinLen); if ((unsigned long)text.size()<_minPinLen) _pin->setToolTip(tr("minimum PIN length: %1").arg(_minPinLen)); if ((unsigned long)text.size()>_maxPinLen) _pin->setToolTip(tr("maximum PIN length: %1").arg(_maxPinLen)); } protected: QString utfConv(const QString& txt) { QByteArray value(txt.toUtf8()); for (int i(-1); (i=value.indexOf("\\x"))!=-1 && i+3