Changeset View
Changeset View
Standalone View
Standalone View
src/address.cpp
Show First 20 Lines • Show All 570 Lines • ▼ Show 20 Line(s) | 559 | { | |||
---|---|---|---|---|---|
571 | str += QStringLiteral(" Country: %1\n").arg(d->mCountry); | 571 | str += QStringLiteral(" Country: %1\n").arg(d->mCountry); | ||
572 | str += QStringLiteral(" Label: %1\n").arg(d->mLabel); | 572 | str += QStringLiteral(" Label: %1\n").arg(d->mLabel); | ||
573 | str += QStringLiteral(" Geo: %1\n").arg(d->mGeo.toString()); | 573 | str += QStringLiteral(" Geo: %1\n").arg(d->mGeo.toString()); | ||
574 | str += QLatin1String("}\n"); | 574 | str += QLatin1String("}\n"); | ||
575 | 575 | | |||
576 | return str; | 576 | return str; | ||
577 | } | 577 | } | ||
578 | 578 | | |||
579 | static QString countryCodeFromLocale() | ||||
580 | { | ||||
581 | const auto n = QLocale().name(); // this is in the form <lang>_<COUNTRY>, with the exception of 'C' | ||||
582 | const auto idx = n.indexOf(QLatin1Char('_')); | ||||
583 | if (idx > 0) { | ||||
584 | return n.mid(idx + 1).toLower(); | ||||
585 | } | ||||
586 | return {}; | ||||
587 | } | ||||
588 | | ||||
579 | QString Address::formattedAddress(const QString &realName, const QString &orgaName) const | 589 | QString Address::formattedAddress(const QString &realName, const QString &orgaName) const | ||
580 | { | 590 | { | ||
581 | QString ciso; | 591 | QString ciso; | ||
582 | QString addrTemplate; | 592 | QString addrTemplate; | ||
583 | QString ret; | 593 | QString ret; | ||
584 | 594 | | |||
585 | // FIXME: first check for iso-country-field and prefer that one | 595 | // FIXME: first check for iso-country-field and prefer that one | ||
586 | if (!country().isEmpty()) { | 596 | if (!country().isEmpty()) { | ||
587 | ciso = countryToISO(country()); | 597 | ciso = countryToISO(country()); | ||
588 | } else { | 598 | } else { | ||
589 | // fall back to our own country | 599 | // fall back to our own country | ||
590 | ciso = QLocale().bcp47Name(); | 600 | ciso = countryCodeFromLocale(); | ||
591 | } | 601 | } | ||
592 | KConfig entry(QStringLiteral(":/org.kde.kcontacts/addressformatrc")); | 602 | KConfig entry(QStringLiteral(":/org.kde.kcontacts/addressformatrc")); | ||
593 | 603 | | |||
594 | KConfigGroup group = entry.group(ciso); | 604 | KConfigGroup group = entry.group(ciso); | ||
595 | // decide whether this needs special business address formatting | 605 | // decide whether this needs special business address formatting | ||
596 | if (orgaName.isEmpty()) { | 606 | if (orgaName.isEmpty()) { | ||
597 | addrTemplate = group.readEntry("AddressFormat"); | 607 | addrTemplate = group.readEntry("AddressFormat"); | ||
598 | } else { | 608 | } else { | ||
Show All 13 Lines | |||||
612 | } | 622 | } | ||
613 | 623 | | |||
614 | // scan | 624 | // scan | ||
615 | parseAddressTemplateSection(addrTemplate, ret, realName, orgaName, *this); | 625 | parseAddressTemplateSection(addrTemplate, ret, realName, orgaName, *this); | ||
616 | 626 | | |||
617 | // now add the country line if needed (formatting this time according to | 627 | // now add the country line if needed (formatting this time according to | ||
618 | // the rules of our own system country ) | 628 | // the rules of our own system country ) | ||
619 | if (!country().isEmpty()) { | 629 | if (!country().isEmpty()) { | ||
620 | KConfigGroup group = entry.group(QLocale().name()); | 630 | KConfigGroup group = entry.group(countryCodeFromLocale()); | ||
621 | QString cpos = group.readEntry("AddressCountryPosition"); | 631 | QString cpos = group.readEntry("AddressCountryPosition"); | ||
622 | if (QLatin1String("BELOW") == cpos || cpos.isEmpty()) { | 632 | if (QLatin1String("BELOW") == cpos || cpos.isEmpty()) { | ||
623 | ret = ret + QLatin1String("\n\n") + country().toUpper(); | 633 | ret = ret + QLatin1String("\n\n") + country().toUpper(); | ||
624 | } else if (QLatin1String("below") == cpos) { | 634 | } else if (QLatin1String("below") == cpos) { | ||
625 | ret = ret + QLatin1String("\n\n") + country(); | 635 | ret = ret + QLatin1String("\n\n") + country(); | ||
626 | } else if (QLatin1String("ABOVE") == cpos) { | 636 | } else if (QLatin1String("ABOVE") == cpos) { | ||
627 | ret = country().toUpper() + QLatin1String("\n\n") + ret; | 637 | ret = country().toUpper() + QLatin1String("\n\n") + ret; | ||
628 | } else if (QLatin1String("above") == cpos) { | 638 | } else if (QLatin1String("above") == cpos) { | ||
▲ Show 20 Lines • Show All 87 Lines • Show Last 20 Lines |