Changeset View
Changeset View
Standalone View
Standalone View
Modules/about-distro/src/Entry.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | SPDX-FileCopyrightText: 2012-2020 Harald Sitter <sitter@kde.org> | ||||
3 | SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL | ||||
4 | */ | ||||
5 | | ||||
6 | #include "Entry.h" | ||||
7 | | ||||
8 | Entry::Entry(const KLocalizedString &label_, const QString &value_) | ||||
9 | : label(label_) | ||||
10 | , value(value_) | ||||
11 | { | ||||
12 | Q_ASSERT(label.isEmpty() || localizedLabel(Language::English).endsWith(':')); | ||||
13 | } | ||||
14 | | ||||
15 | Entry::~Entry() = default; | ||||
16 | | ||||
17 | // When false this entry is garbage (e.g. incomplete data) and shouldn't be rendered. | ||||
18 | bool Entry::isValid() const | ||||
19 | { | ||||
20 | return !label.toString().isEmpty() && !value.isEmpty(); | ||||
21 | } | ||||
22 | | ||||
23 | // Returns textual representation of entry. | ||||
24 | QString Entry::diagnosticLine(Language language) const | ||||
25 | { | ||||
26 | // FIXME: This isn't really working for right-to-left | ||||
27 | // The answer probably is in uncide control characters, but | ||||
28 | // didn't work when tried. | ||||
29 | // Essentially what needs to happen is that the label should be RTL | ||||
30 | // that is to say the colon should be on the left, BUT englishy words | ||||
31 | // within that should be LTR, everything besides the label should be LTR | ||||
32 | // because we do not localize the values I don't think? | ||||
33 | return localizedLabel(language) + ' ' + value + '\n'; | ||||
34 | } | ||||
35 | | ||||
36 | QString Entry::localizedLabel(Language language) const | ||||
37 | { | ||||
38 | switch (language) { | ||||
39 | case Language::System: | ||||
40 | return label.toString(); | ||||
41 | case Language::English: | ||||
42 | // https://bugs.kde.org/show_bug.cgi?id=416247 | ||||
43 | return label.toString(QStringList { QStringLiteral("en_US") }); | ||||
44 | } | ||||
45 | Q_UNREACHABLE(); | ||||
46 | return QStringLiteral("Unknown Label Language %1 (bug in KInfocenter!):").arg( | ||||
47 | QString::number(static_cast<int>(language))); | ||||
48 | } |