Changeset View
Changeset View
Standalone View
Standalone View
Modules/about-distro/src/Entry.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright (C) 2012-2020 Harald Sitter <sitter@kde.org> | ||||
3 | | ||||
4 | This program is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU General Public License as | ||||
6 | published by the Free Software Foundation; either version 2 of | ||||
7 | the License or (at your option) version 3 or any later version | ||||
8 | accepted by the membership of KDE e.V. (or its successor approved | ||||
9 | by the membership of KDE e.V.), which shall act as a proxy | ||||
10 | defined in Section 14 of version 3 of the license. | ||||
11 | | ||||
12 | This program is distributed in the hope that it will be useful, | ||||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | GNU General Public License for more details. | ||||
16 | | ||||
17 | You should have received a copy of the GNU General Public License | ||||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | #include "Entry.h" | ||||
22 | | ||||
23 | Entry::Entry(const KLocalizedString &label_, const QString &value_) | ||||
24 | : label(label_) | ||||
25 | , value(value_) | ||||
26 | { | ||||
27 | Q_ASSERT(label.isEmpty() || localizedLabel(Language::English).endsWith(':')); | ||||
28 | } | ||||
29 | | ||||
30 | Entry::~Entry() = default; | ||||
31 | | ||||
32 | // When false this entry is garbage (e.g. incomplete data) and shouldn't be rendered. | ||||
33 | bool Entry::isValid() const | ||||
34 | { | ||||
35 | return !label.toString().isEmpty() && !value.isEmpty(); | ||||
36 | } | ||||
37 | | ||||
38 | // Returns textual representation of entry. | ||||
39 | QString Entry::diagnosticLine(Language language) const | ||||
40 | { | ||||
41 | // FIXME: This isn't really working for right-to-left | ||||
42 | // The answer probably is in uncide control characters, but | ||||
43 | // didn't work when tried. | ||||
44 | // Essentially what needs to happen is that the label should be RTL | ||||
45 | // that is to say the colon should be on the left, BUT englishy words | ||||
46 | // within that should be LTR, everything besides the label should be LTR | ||||
47 | // because we do not localize the values I don't think? | ||||
48 | return localizedLabel(language) + ' ' + value + '\n'; | ||||
49 | } | ||||
50 | | ||||
51 | QString Entry::localizedLabel(Language language) const | ||||
52 | { | ||||
53 | switch (language) { | ||||
54 | case Language::System: | ||||
55 | return label.toString(); | ||||
56 | case Language::English: | ||||
57 | // https://bugs.kde.org/show_bug.cgi?id=416247 | ||||
58 | return label.toString(QStringList { QStringLiteral("en_US") }); | ||||
59 | } | ||||
60 | Q_UNREACHABLE(); | ||||
61 | return QStringLiteral("Unknown Label Language %1 (bug in KInfocenter!):").arg( | ||||
62 | QString::number(static_cast<int>(language))); | ||||
63 | } |