Changeset View
Changeset View
Standalone View
Standalone View
src/newcertificatewizard/newcertificatewizard.cpp
Show First 20 Lines • Show All 271 Lines • ▼ Show 20 Line(s) | 271 | #define FIELD(type, name) type name() const { return field( QLatin1String(#name) ).value<type>(); } | |||
---|---|---|---|---|---|
272 | FIELD(bool, pgp) | 272 | FIELD(bool, pgp) | ||
273 | FIELD(bool, signingAllowed) | 273 | FIELD(bool, signingAllowed) | ||
274 | FIELD(bool, encryptionAllowed) | 274 | FIELD(bool, encryptionAllowed) | ||
275 | FIELD(bool, certificationAllowed) | 275 | FIELD(bool, certificationAllowed) | ||
276 | FIELD(bool, authenticationAllowed) | 276 | FIELD(bool, authenticationAllowed) | ||
277 | 277 | | |||
278 | FIELD(QString, name) | 278 | FIELD(QString, name) | ||
279 | FIELD(QString, email) | 279 | FIELD(QString, email) | ||
280 | FIELD(QString, comment) | | |||
281 | FIELD(QString, dn) | 280 | FIELD(QString, dn) | ||
282 | 281 | | |||
283 | FIELD(Subkey::PubkeyAlgo, keyType) | 282 | FIELD(Subkey::PubkeyAlgo, keyType) | ||
284 | FIELD(int, keyStrength) | 283 | FIELD(int, keyStrength) | ||
285 | FIELD(QString, keyCurve) | 284 | FIELD(QString, keyCurve) | ||
286 | 285 | | |||
287 | FIELD(Subkey::PubkeyAlgo, subkeyType) | 286 | FIELD(Subkey::PubkeyAlgo, subkeyType) | ||
288 | FIELD(int, subkeyStrength) | 287 | FIELD(int, subkeyStrength) | ||
▲ Show 20 Lines • Show All 395 Lines • ▼ Show 20 Line(s) | 672 | { | |||
684 | connect(ui.emailLE, &QLineEdit::textChanged, | 683 | connect(ui.emailLE, &QLineEdit::textChanged, | ||
685 | this, &QWizardPage::completeChanged); | 684 | this, &QWizardPage::completeChanged); | ||
686 | connect(ui.addEmailToDnCB, &QAbstractButton::toggled, | 685 | connect(ui.addEmailToDnCB, &QAbstractButton::toggled, | ||
687 | this, &EnterDetailsPage::slotUpdateResultLabel); | 686 | this, &EnterDetailsPage::slotUpdateResultLabel); | ||
688 | registerDialogPropertiesAsFields(); | 687 | registerDialogPropertiesAsFields(); | ||
689 | registerField(QStringLiteral("dn"), ui.resultLE); | 688 | registerField(QStringLiteral("dn"), ui.resultLE); | ||
690 | registerField(QStringLiteral("name"), ui.nameLE); | 689 | registerField(QStringLiteral("name"), ui.nameLE); | ||
691 | registerField(QStringLiteral("email"), ui.emailLE); | 690 | registerField(QStringLiteral("email"), ui.emailLE); | ||
692 | registerField(QStringLiteral("comment"), ui.commentLE); | | |||
693 | updateForm(); | 691 | updateForm(); | ||
694 | } | 692 | } | ||
695 | 693 | | |||
696 | bool isComplete() const override; | 694 | bool isComplete() const override; | ||
697 | void initializePage() override { | 695 | void initializePage() override { | ||
698 | updateForm(); | 696 | updateForm(); | ||
699 | dialog.setProtocol(pgp() ? OpenPGP : CMS); | 697 | dialog.setProtocol(pgp() ? OpenPGP : CMS); | ||
700 | } | 698 | } | ||
▲ Show 20 Lines • Show All 482 Lines • ▼ Show 20 Line(s) | 1180 | { | |||
1183 | return d->ui.chooseProtocolPage.protocol(); | 1181 | return d->ui.chooseProtocolPage.protocol(); | ||
1184 | } | 1182 | } | ||
1185 | 1183 | | |||
1186 | static QString pgpLabel(const QString &attr) | 1184 | static QString pgpLabel(const QString &attr) | ||
1187 | { | 1185 | { | ||
1188 | if (attr == QLatin1String("NAME")) { | 1186 | if (attr == QLatin1String("NAME")) { | ||
1189 | return i18n("Name"); | 1187 | return i18n("Name"); | ||
1190 | } | 1188 | } | ||
1191 | if (attr == QLatin1String("COMMENT")) { | | |||
1192 | return i18n("Comment"); | | |||
1193 | } | | |||
1194 | if (attr == QLatin1String("EMAIL")) { | 1189 | if (attr == QLatin1String("EMAIL")) { | ||
1195 | return i18n("EMail"); | 1190 | return i18n("EMail"); | ||
1196 | } | 1191 | } | ||
1197 | return QString(); | 1192 | return QString(); | ||
1198 | } | 1193 | } | ||
1199 | 1194 | | |||
1200 | static QString attributeLabel(const QString &attr, bool pgp) | 1195 | static QString attributeLabel(const QString &attr, bool pgp) | ||
1201 | { | 1196 | { | ||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Line(s) | 1266 | { | |||
1278 | ui.nameLB->hide(); | 1273 | ui.nameLB->hide(); | ||
1279 | ui.nameRequiredLB->hide(); | 1274 | ui.nameRequiredLB->hide(); | ||
1280 | 1275 | | |||
1281 | ui.emailLE->hide(); | 1276 | ui.emailLE->hide(); | ||
1282 | ui.emailLE->clear(); | 1277 | ui.emailLE->clear(); | ||
1283 | ui.emailLB->hide(); | 1278 | ui.emailLB->hide(); | ||
1284 | ui.emailRequiredLB->hide(); | 1279 | ui.emailRequiredLB->hide(); | ||
1285 | 1280 | | |||
1286 | ui.commentLE->hide(); | | |||
1287 | ui.commentLE->clear(); | | |||
1288 | ui.commentLB->hide(); | | |||
1289 | ui.commentRequiredLB->hide(); | | |||
1290 | | ||||
1291 | ui.addEmailToDnCB->hide(); | 1281 | ui.addEmailToDnCB->hide(); | ||
1292 | } | 1282 | } | ||
1293 | 1283 | | |||
1294 | static int row_index_of(QWidget *w, QGridLayout *l) | 1284 | static int row_index_of(QWidget *w, QGridLayout *l) | ||
1295 | { | 1285 | { | ||
1296 | const int idx = l->indexOf(w); | 1286 | const int idx = l->indexOf(w); | ||
1297 | int r, c, rs, cs; | 1287 | int r, c, rs, cs; | ||
1298 | l->getItemPosition(idx, &r, &c, &rs, &cs); | 1288 | l->getItemPosition(idx, &r, &c, &rs, &cs); | ||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Line(s) | 1342 | { | |||
1353 | 1343 | | |||
1354 | clearForm(); | 1344 | clearForm(); | ||
1355 | 1345 | | |||
1356 | const KConfigGroup config(KSharedConfig::openConfig(), "CertificateCreationWizard"); | 1346 | const KConfigGroup config(KSharedConfig::openConfig(), "CertificateCreationWizard"); | ||
1357 | 1347 | | |||
1358 | QStringList attrOrder = config.readEntry(pgp() ? "OpenPGPAttributeOrder" : "DNAttributeOrder", QStringList()); | 1348 | QStringList attrOrder = config.readEntry(pgp() ? "OpenPGPAttributeOrder" : "DNAttributeOrder", QStringList()); | ||
1359 | if (attrOrder.empty()) { | 1349 | if (attrOrder.empty()) { | ||
1360 | if (pgp()) { | 1350 | if (pgp()) { | ||
1361 | attrOrder << QStringLiteral("NAME!") << QStringLiteral("EMAIL!") << QStringLiteral("COMMENT"); | 1351 | attrOrder << QStringLiteral("NAME!") << QStringLiteral("EMAIL!"); | ||
1362 | } else { | 1352 | } else { | ||
1363 | attrOrder << QStringLiteral("CN!") << QStringLiteral("L") << QStringLiteral("OU") << QStringLiteral("O!") << QStringLiteral("C!") << QStringLiteral("EMAIL!"); | 1353 | attrOrder << QStringLiteral("CN!") << QStringLiteral("L") << QStringLiteral("OU") << QStringLiteral("O!") << QStringLiteral("C!") << QStringLiteral("EMAIL!"); | ||
1364 | } | 1354 | } | ||
1365 | } | 1355 | } | ||
1366 | 1356 | | |||
1367 | QList<QWidget *> widgets; | 1357 | QList<QWidget *> widgets; | ||
1368 | widgets.push_back(ui.nameLE); | 1358 | widgets.push_back(ui.nameLE); | ||
1369 | widgets.push_back(ui.emailLE); | 1359 | widgets.push_back(ui.emailLE); | ||
1370 | widgets.push_back(ui.commentLE); | | |||
1371 | 1360 | | |||
1372 | QMap<int, Line> lines; | 1361 | QMap<int, Line> lines; | ||
1373 | 1362 | | |||
1374 | Q_FOREACH (const QString &rawKey, attrOrder) { | 1363 | Q_FOREACH (const QString &rawKey, attrOrder) { | ||
1375 | const QString key = rawKey.trimmed().toUpper(); | 1364 | const QString key = rawKey.trimmed().toUpper(); | ||
1376 | const QString attr = attributeFromKey(key); | 1365 | const QString attr = attributeFromKey(key); | ||
1377 | if (attr.isEmpty()) { | 1366 | if (attr.isEmpty()) { | ||
1378 | continue; | 1367 | continue; | ||
Show All 17 Lines | |||||
1396 | } else if (attr == QLatin1String("NAME") || attr == QLatin1String("CN")) { | 1385 | } else if (attr == QLatin1String("NAME") || attr == QLatin1String("CN")) { | ||
1397 | if ((pgp() && attr == QLatin1String("CN")) || (!pgp() && attr == QLatin1String("NAME"))) { | 1386 | if ((pgp() && attr == QLatin1String("CN")) || (!pgp() && attr == QLatin1String("NAME"))) { | ||
1398 | continue; | 1387 | continue; | ||
1399 | } | 1388 | } | ||
1400 | if (pgp()) { | 1389 | if (pgp()) { | ||
1401 | validator = regex.isEmpty() ? Validation::pgpName() : Validation::pgpName(QRegExp(regex)); | 1390 | validator = regex.isEmpty() ? Validation::pgpName() : Validation::pgpName(QRegExp(regex)); | ||
1402 | } | 1391 | } | ||
1403 | row = row_index_of(ui.nameLE, ui.gridLayout); | 1392 | row = row_index_of(ui.nameLE, ui.gridLayout); | ||
1404 | } else if (attr == QLatin1String("COMMENT")) { | | |||
1405 | if (!pgp()) { | | |||
1406 | continue; | | |||
1407 | } | | |||
1408 | validator = regex.isEmpty() ? Validation::pgpComment() : Validation::pgpComment(QRegExp(regex)); | | |||
1409 | row = row_index_of(ui.commentLE, ui.gridLayout); | | |||
1410 | } else { | 1393 | } else { | ||
1411 | known = false; | 1394 | known = false; | ||
1412 | row = add_row(ui.gridLayout, &dynamicWidgets); | 1395 | row = add_row(ui.gridLayout, &dynamicWidgets); | ||
1413 | } | 1396 | } | ||
1414 | if (!validator && !regex.isEmpty()) { | 1397 | if (!validator && !regex.isEmpty()) { | ||
1415 | validator = new QRegExpValidator(QRegExp(regex), nullptr); | 1398 | validator = new QRegExpValidator(QRegExp(regex), nullptr); | ||
1416 | } | 1399 | } | ||
1417 | 1400 | | |||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Line(s) | 1436 | { | |||
1469 | return dn.dn(); | 1452 | return dn.dn(); | ||
1470 | } | 1453 | } | ||
1471 | 1454 | | |||
1472 | QString EnterDetailsPage::pgpUserID() const | 1455 | QString EnterDetailsPage::pgpUserID() const | ||
1473 | { | 1456 | { | ||
1474 | return Formatting::prettyNameAndEMail(OpenPGP, QString(), | 1457 | return Formatting::prettyNameAndEMail(OpenPGP, QString(), | ||
1475 | ui.nameLE->text().trimmed(), | 1458 | ui.nameLE->text().trimmed(), | ||
1476 | ui.emailLE->text().trimmed(), | 1459 | ui.emailLE->text().trimmed(), | ||
1477 | ui.commentLE->text().trimmed()); | 1460 | QString()); | ||
dvratil: Use `QString()` or just `{}` instead of `""` | |||||
1478 | } | 1461 | } | ||
1479 | 1462 | | |||
1480 | static bool has_intermediate_input(const QLineEdit *le) | 1463 | static bool has_intermediate_input(const QLineEdit *le) | ||
1481 | { | 1464 | { | ||
1482 | QString text = le->text(); | 1465 | QString text = le->text(); | ||
1483 | int pos = le->cursorPosition(); | 1466 | int pos = le->cursorPosition(); | ||
1484 | const QValidator *const v = le->validator(); | 1467 | const QValidator *const v = le->validator(); | ||
1485 | return v && v->validate(text, pos) == QValidator::Intermediate; | 1468 | return v && v->validate(text, pos) == QValidator::Intermediate; | ||
▲ Show 20 Lines • Show All 141 Lines • ▼ Show 20 Line(s) | |||||
1627 | { | 1610 | { | ||
1628 | QString result; | 1611 | QString result; | ||
1629 | QTextStream s(&result); | 1612 | QTextStream s(&result); | ||
1630 | s << "<table>"; | 1613 | s << "<table>"; | ||
1631 | if (pgp()) { | 1614 | if (pgp()) { | ||
1632 | s << Row< >(i18n("Name:"), name()); | 1615 | s << Row< >(i18n("Name:"), name()); | ||
1633 | } | 1616 | } | ||
1634 | s << Row< >(i18n("Email Address:"), email()); | 1617 | s << Row< >(i18n("Email Address:"), email()); | ||
1635 | if (pgp()) { | 1618 | if (! pgp()) { | ||
1636 | if (!comment().isEmpty()) { | | |||
1637 | s << Row< >(i18n("Comment:"), comment()); | | |||
1638 | } | | |||
1639 | } else { | | |||
1640 | s << Row< >(i18n("Subject-DN:"), DN(dn()).dn(QStringLiteral(",<br>"))); | 1619 | s << Row< >(i18n("Subject-DN:"), DN(dn()).dn(QStringLiteral(",<br>"))); | ||
1641 | } | 1620 | } | ||
1642 | if (details) { | 1621 | if (details) { | ||
1643 | s << Row< >(i18n("Key Type:"), QLatin1String(Subkey::publicKeyAlgorithmAsString(keyType()))); | 1622 | s << Row< >(i18n("Key Type:"), QLatin1String(Subkey::publicKeyAlgorithmAsString(keyType()))); | ||
1644 | if (is_ecdsa(keyType())) { | 1623 | if (is_ecdsa(keyType())) { | ||
1645 | s << Row< >(i18n("Key Curve:"), keyCurve()); | 1624 | s << Row< >(i18n("Key Curve:"), keyCurve()); | ||
1646 | } else if (const unsigned int strength = keyStrength()) { | 1625 | } else if (const unsigned int strength = keyStrength()) { | ||
1647 | s << Row< >(i18n("Key Strength:"), i18np("1 bit", "%1 bits", strength)); | 1626 | s << Row< >(i18n("Key Strength:"), i18np("1 bit", "%1 bits", strength)); | ||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Line(s) | 1690 | if (const Subkey::PubkeyAlgo subkey = subkeyType()) { | |||
1719 | s << "subkey-usage: " << subkeyUsages().join(QLatin1Char(' ')) << endl; | 1698 | s << "subkey-usage: " << subkeyUsages().join(QLatin1Char(' ')) << endl; | ||
1720 | } | 1699 | } | ||
1721 | if (pgp() && expiryDate().isValid()) { | 1700 | if (pgp() && expiryDate().isValid()) { | ||
1722 | s << "expire-date: " << expiryDate().toString(Qt::ISODate) << endl; | 1701 | s << "expire-date: " << expiryDate().toString(Qt::ISODate) << endl; | ||
1723 | } | 1702 | } | ||
1724 | if (pgp()) { | 1703 | if (pgp()) { | ||
1725 | s << "name-real: " << name() << endl; | 1704 | s << "name-real: " << name() << endl; | ||
1726 | s << "name-email: " << email() << endl; | 1705 | s << "name-email: " << email() << endl; | ||
1727 | if (!comment().isEmpty()) { | | |||
1728 | s << "name-comment: " << comment() << endl; | | |||
1729 | } | | |||
1730 | } else { | 1706 | } else { | ||
1731 | s << "name-dn: " << dn() << endl; | 1707 | s << "name-dn: " << dn() << endl; | ||
1732 | s << "name-email: " << encode_email(email()) << endl; | 1708 | s << "name-email: " << encode_email(email()) << endl; | ||
1733 | Q_FOREACH (const QString &email, additionalEMailAddresses()) { | 1709 | Q_FOREACH (const QString &email, additionalEMailAddresses()) { | ||
1734 | s << "name-email: " << encode_email(email) << endl; | 1710 | s << "name-email: " << encode_email(email) << endl; | ||
1735 | } | 1711 | } | ||
1736 | Q_FOREACH (const QString &dns, dnsNames()) { | 1712 | Q_FOREACH (const QString &dns, dnsNames()) { | ||
1737 | s << "name-dns: " << encode_dns(dns) << endl; | 1713 | s << "name-dns: " << encode_dns(dns) << endl; | ||
▲ Show 20 Lines • Show All 136 Lines • Show Last 20 Lines |
Use QString() or just {} instead of ""