From ba1d8e2c4d90bd1129b3b1f42574effc8813c55b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Str=C3=B8mme?= Date: Thu, 29 Aug 2013 18:53:52 +0200 Subject: Android: Improve the Keystore and Certificate dialog. - Display all information in one place. - Checkbox to enable the certificate to use the same password as the Keystore. - Display information when alias field is empty. - Misc. layout changes. Task-number: QTCREATORBUG-10061 Change-Id: I99a3e7019dfbf72bcd2374594f3ebe45c26680d2 Reviewed-by: Daniel Teske Reviewed-by: BogDan Vatra --- .../android/androidcreatekeystorecertificate.cpp | 145 +++++++---- .../android/androidcreatekeystorecertificate.h | 4 + .../android/androidcreatekeystorecertificate.ui | 289 +++++++++++---------- 3 files changed, 247 insertions(+), 191 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/android/androidcreatekeystorecertificate.cpp b/src/plugins/android/androidcreatekeystorecertificate.cpp index 6f006a2d816..5fc5dc02858 100644 --- a/src/plugins/android/androidcreatekeystorecertificate.cpp +++ b/src/plugins/android/androidcreatekeystorecertificate.cpp @@ -46,6 +46,8 @@ AndroidCreateKeystoreCertificate::AndroidCreateKeystoreCertificate(QWidget *pare connect(ui->keystoreRetypePassLineEdit, SIGNAL(textChanged(QString)), this, SLOT(checkKeystorePassword())); connect(ui->certificatePassLineEdit, SIGNAL(textChanged(QString)), this, SLOT(checkCertificatePassword())); connect(ui->certificateRetypePassLineEdit, SIGNAL(textChanged(QString)), this, SLOT(checkCertificatePassword())); + connect(ui->certificateAliasLineEdit, SIGNAL(textChanged(QString)), this, SLOT(checkCertificateAlias())); + connect(ui->countryLineEdit, SIGNAL(textChanged(QString)), this, SLOT(checkCountryCode())); } AndroidCreateKeystoreCertificate::~AndroidCreateKeystoreCertificate() @@ -65,42 +67,71 @@ QString AndroidCreateKeystoreCertificate::keystorePassword() QString AndroidCreateKeystoreCertificate::certificateAlias() { - return ui->aliasNameLineEdit->text(); + return ui->certificateAliasLineEdit->text(); } QString AndroidCreateKeystoreCertificate::certificatePassword() { - return ui->certificatePassLineEdit->text(); + return (ui->samePasswordCheckBox->checkState() == Qt::Checked) + ? keystorePassword() + : ui->certificatePassLineEdit->text(); } AndroidCreateKeystoreCertificate::PasswordStatus AndroidCreateKeystoreCertificate::checkKeystorePassword() { if (ui->keystorePassLineEdit->text().length() < 6) { - ui->keystorePassInfoLabel->setText(tr("Password is too short")); + ui->infoLabel->setText(tr("Keystore password is too short")); return Invalid; } if (ui->keystorePassLineEdit->text() != ui->keystoreRetypePassLineEdit->text()) { - ui->keystorePassInfoLabel->setText(tr("Passwords don't match")); + ui->infoLabel->setText(tr("Keystore passwords do not match")); return NoMatch; } - ui->keystorePassInfoLabel->setText(tr("Password is ok")); + + ui->infoLabel->clear(); return Match; } AndroidCreateKeystoreCertificate::PasswordStatus AndroidCreateKeystoreCertificate::checkCertificatePassword() { + if (ui->samePasswordCheckBox->checkState() == Qt::Checked) + return Match; + if (ui->certificatePassLineEdit->text().length() < 6) { - ui->certificatePassInfoLabel->setText(tr("Password is too short")); + ui->infoLabel->setText(tr("Certificate password is too short")); return Invalid; } if (ui->certificatePassLineEdit->text() != ui->certificateRetypePassLineEdit->text()) { - ui->certificatePassInfoLabel->setText(tr("Passwords don't match")); + ui->infoLabel->setText(tr("Certificate passwords do not match")); return NoMatch; } - ui->certificatePassInfoLabel->setText(tr("Password is ok")); + + ui->infoLabel->clear(); return Match; } +bool AndroidCreateKeystoreCertificate::checkCertificateAlias() +{ + if (ui->certificateAliasLineEdit->text().length() == 0) { + ui->infoLabel->setText(tr("Certificate alias is missing")); + return false; + } + + ui->infoLabel->clear(); + return true; +} + +bool AndroidCreateKeystoreCertificate::checkCountryCode() +{ + if (!ui->countryLineEdit->text().contains(QRegExp(QLatin1String("[A-Z]{2}")))) { + ui->infoLabel->setText(tr("Invalid country code")); + return false; + } + + ui->infoLabel->clear(); + return true; +} + void AndroidCreateKeystoreCertificate::on_keystoreShowPassCheckBox_stateChanged(int state) { ui->keystorePassLineEdit->setEchoMode(state == Qt::Checked ? QLineEdit::Normal : QLineEdit::Password); @@ -115,44 +146,8 @@ void AndroidCreateKeystoreCertificate::on_certificateShowPassCheckBox_stateChang void AndroidCreateKeystoreCertificate::on_buttonBox_accepted() { - switch (checkKeystorePassword()) { - case Invalid: - ui->keystorePassLineEdit->setFocus(); - return; - case NoMatch: - ui->keystoreRetypePassLineEdit->setFocus(); + if (!validateUserInput()) return; - default: - break; - } - - switch (checkCertificatePassword()) { - case Invalid: - ui->certificatePassLineEdit->setFocus(); - return; - case NoMatch: - ui->certificateRetypePassLineEdit->setFocus(); - return; - default: - break; - } - - if (!ui->aliasNameLineEdit->text().length()) { - ui->aliasNameLineEdit->setFocus(); - return; - } - - if (!ui->commonNameLineEdit->text().length()) - ui->commonNameLineEdit->setFocus(); - - if (!ui->organizationNameLineEdit->text().length()) - ui->organizationNameLineEdit->setFocus(); - - if (!ui->localityNameLineEdit->text().length()) - ui->localityNameLineEdit->setFocus(); - - if (!ui->countryLineEdit->text().length()) - ui->countryLineEdit->setFocus(); m_keystoreFilePath = Utils::FileName::fromString(QFileDialog::getSaveFileName(this, tr("Keystore file name"), QDir::homePath() + QLatin1String("/android_release.keystore"), @@ -174,11 +169,11 @@ void AndroidCreateKeystoreCertificate::on_buttonBox_accepted() QStringList params; params << QLatin1String("-genkey") << QLatin1String("-keyalg") << QLatin1String("RSA") << QLatin1String("-keystore") << m_keystoreFilePath.toString() - << QLatin1String("-storepass") << ui->keystorePassLineEdit->text() - << QLatin1String("-alias") << ui->aliasNameLineEdit->text() + << QLatin1String("-storepass") << keystorePassword() + << QLatin1String("-alias") << certificateAlias() << QLatin1String("-keysize") << ui->keySizeSpinBox->text() << QLatin1String("-validity") << ui->validitySpinBox->text() - << QLatin1String("-keypass") << ui->certificatePassLineEdit->text() + << QLatin1String("-keypass") << certificatePassword() << QLatin1String("-dname") << distinguishedNames; QProcess genKeyCertProc; @@ -195,3 +190,57 @@ void AndroidCreateKeystoreCertificate::on_buttonBox_accepted() } accept(); } + +void AndroidCreateKeystoreCertificate::on_samePasswordCheckBox_stateChanged(int state) +{ + if (state == Qt::Checked) { + ui->certificatePassLineEdit->setDisabled(true); + ui->certificateRetypePassLineEdit->setDisabled(true); + ui->certificateShowPassCheckBox->setDisabled(true); + } + + if (state == Qt::Unchecked) { + ui->certificatePassLineEdit->setEnabled(true); + ui->certificateRetypePassLineEdit->setEnabled(true); + ui->certificateShowPassCheckBox->setEnabled(true); + } + + validateUserInput(); +} + +bool AndroidCreateKeystoreCertificate::validateUserInput() +{ + switch (checkKeystorePassword()) { + case Invalid: + ui->keystorePassLineEdit->setFocus(); + return false; + case NoMatch: + ui->keystoreRetypePassLineEdit->setFocus(); + return false; + default: + break; + } + + if (!checkCertificateAlias()) { + ui->certificateAliasLineEdit->setFocus(); + return false; + } + + switch (checkCertificatePassword()) { + case Invalid: + ui->certificatePassLineEdit->setFocus(); + return false; + case NoMatch: + ui->certificateRetypePassLineEdit->setFocus(); + return false; + default: + break; + } + + if (!checkCountryCode()) { + ui->countryLineEdit->setFocus(); + return false; + } + + return true; +} diff --git a/src/plugins/android/androidcreatekeystorecertificate.h b/src/plugins/android/androidcreatekeystorecertificate.h index 5df88bef8b7..021a52b188f 100644 --- a/src/plugins/android/androidcreatekeystorecertificate.h +++ b/src/plugins/android/androidcreatekeystorecertificate.h @@ -62,11 +62,15 @@ public: private slots: PasswordStatus checkKeystorePassword(); PasswordStatus checkCertificatePassword(); + bool checkCertificateAlias(); + bool checkCountryCode(); void on_keystoreShowPassCheckBox_stateChanged(int state); void on_certificateShowPassCheckBox_stateChanged(int state); void on_buttonBox_accepted(); + void on_samePasswordCheckBox_stateChanged(int state); private: + bool validateUserInput(); Ui::AndroidCreateKeystoreCertificate *ui; Utils::FileName m_keystoreFilePath; }; diff --git a/src/plugins/android/androidcreatekeystorecertificate.ui b/src/plugins/android/androidcreatekeystorecertificate.ui index ed0d4ecf8b7..51c66939f5d 100644 --- a/src/plugins/android/androidcreatekeystorecertificate.ui +++ b/src/plugins/android/androidcreatekeystorecertificate.ui @@ -7,23 +7,23 @@ 0 0 638 - 429 + 473 Create a keystore and a certificate - - + + - Keystore + Certificate Distinguished Names - + - + - Password: + First and last name: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -31,16 +31,12 @@ - - - QLineEdit::Password - - + - + - Retype password: + Organizational unit (e.g. Necessitas): Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -48,78 +44,97 @@ - - - QLineEdit::Password - - + - + - Show password + Organization (e.g. KDE): + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - + + + + - <span style=" color:#ff0000;">Password is too short</span> + City or locality: - - Qt::RichText + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + State or province: - Qt::AlignCenter + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Certificate - - - - + + + + + - Alias name: + Two-letter country code for this unit (e.g. RO): Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + - Aaaaaaaa; + - 8 + 2 - - - - Keysize: + + + + + + + Certificate + + + + + + QLineEdit::Password - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + Show password - - + + - 2048 + 10000 - 2097152 + 100000 @@ -133,13 +148,13 @@ - - - - 10000 + + + + Alias name: - - 100000 + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -153,148 +168,127 @@ - - - - QLineEdit::Password + + + + + + + 8 - - + + - Retype password: + Keysize: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + QLineEdit::Password - - - - Show password - - - - - - - <span style=" color:#ff0000;">Password is too short</span> - - - Qt::RichText + + + + 2048 - - Qt::AlignCenter + + 2097152 - - - - - - - Certificate Distinguished Names - - - - + + - First and last name: + Retype password: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - + + - Organizational unit (e.g. Necessitas): - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + Use Keystore password + + + + + + + Keystore + + - - - - - - Organization (e.g. KDE): - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + QLineEdit::Password - + + + QLineEdit::Password + + - + - City or locality: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + Show password - - - - - + + - State or province: + Password: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - + + - Two-letter country code for this unit (e.g. RO): + Retype password: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - >AA; - - - 2 - - + + + + Qt::Vertical + + + + 20 + 40 + + + - + Qt::Horizontal @@ -304,12 +298,22 @@ + + + + + + + Qt::AlignCenter + + + keystorePassLineEdit keystoreRetypePassLineEdit - aliasNameLineEdit + certificateAliasLineEdit keySizeSpinBox validitySpinBox certificatePassLineEdit @@ -321,7 +325,6 @@ stateNameLineEdit countryLineEdit keystoreShowPassCheckBox - certificateShowPassCheckBox buttonBox -- cgit v1.2.3