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 #ifndef ENTRY_H 7 #define ENTRY_H 8 9 #include <KLocalizedString> 10 #include <QLocale> 11 #include <QObject> 12 #include <QString> 13 14 // Generic dumpable info entry. 15 // This encapsulates a table entry so that it may be put into the UI 16 // and also serialized into textual form for copy to clipboard. 17 // All entries that are meant to be serializable should derive from this! 18 // This class may either be subclassed or used as-is if label/value are trivial 19 // to obtain. 20 class Entry : public QObject 21 { 22 Q_OBJECT 23 Q_DISABLE_COPY_MOVE(Entry) 24 public: 25 enum class Language { 26 System, 27 English, 28 }; 29 Q_ENUM(Language); 30 31 // value may be empty if localizedValue is overridden 32 Entry(const KLocalizedString &label_, const QString &value_); 33 ~Entry() override; 34 35 // When false this entry is garbage (e.g. incomplete data) and shouldn't be rendered. 36 bool isValid() const; 37 38 // Returns textual representation of entry. 39 QString diagnosticLine(Language language = Language::System) const; 40 41 Q_SCRIPTABLE QString localizedLabel(Language language = Language::System) const; 42 43 // Returns the value by default. Needs to be overridden in subclasses if localization 44 // is needed for the value. 45 Q_SCRIPTABLE virtual QString localizedValue(Language language = Language::System) const; 46 47 protected: 48 // Returns localized QString for the given language. 49 QString localize(const KLocalizedString &string, Language language) const; 50 51 // Returns a QLocale for the given language. 52 QLocale localeForLanguage(Language language) const; 53 54 // Descriptive label 55 KLocalizedString m_label; 56 // Value of the entry (e.g. the version of plasma) 57 QString m_value; 58 }; 59 60 #endif // ENTRY_H 61