Changeset View
Changeset View
Standalone View
Standalone View
kcms/translations/translationsmodel.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2014 John Layt <john@layt.net> | ||||
3 | * Copyright (C) 2018 Eike Hein <hein@kde.org> | ||||
4 | * | ||||
5 | * This library is free software; you can redistribute it and/or | ||||
6 | * modify it under the terms of the GNU Library General Public | ||||
7 | * License as published by the Free Software Foundation; either | ||||
8 | * version 2 of the License, or (at your option) any later version. | ||||
9 | * | ||||
10 | * This library is distributed in the hope that it will be useful, | ||||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
13 | * Library General Public License for more details. | ||||
14 | * | ||||
15 | * You should have received a copy of the GNU Library General Public License | ||||
16 | * along with this library; see the file COPYING.LIB. If not, write to | ||||
17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
18 | * Boston, MA 02110-1301, USA. | ||||
19 | */ | ||||
20 | | ||||
21 | #ifndef TRANSLATIONSMODEL_H | ||||
22 | #define TRANSLATIONSMODEL_H | ||||
23 | | ||||
24 | #include <QAbstractListModel> | ||||
25 | | ||||
26 | #include <KConfigGroup> | ||||
27 | | ||||
28 | #include <QSet> | ||||
29 | | ||||
30 | class TranslationsModel : public QAbstractListModel | ||||
31 | { | ||||
32 | Q_OBJECT | ||||
33 | | ||||
34 | Q_PROPERTY(QStringList selectedLanguages READ selectedLanguages WRITE setSelectedLanguages NOTIFY selectedLanguagesChanged) | ||||
35 | Q_PROPERTY(QStringList missingLanguages READ missingLanguages NOTIFY missingLanguagesChanged) | ||||
36 | | ||||
37 | public: | ||||
38 | enum AdditionalRoles { | ||||
39 | LanguageCode = Qt::UserRole + 1, | ||||
40 | IsSelected, | ||||
41 | SelectedPriority, | ||||
42 | IsMissing | ||||
43 | }; | ||||
44 | Q_ENUM(AdditionalRoles) | ||||
45 | | ||||
46 | explicit TranslationsModel(QObject *parent = nullptr); | ||||
47 | ~TranslationsModel() override; | ||||
48 | | ||||
49 | QHash<int, QByteArray> roleNames() const override; | ||||
50 | | ||||
51 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; | ||||
52 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; | ||||
53 | | ||||
54 | QStringList selectedLanguages() const; | ||||
55 | void setSelectedLanguages(const QStringList &languages); | ||||
56 | | ||||
57 | QStringList missingLanguages() const; | ||||
58 | | ||||
59 | Q_SIGNALS: | ||||
60 | void selectedLanguagesChanged() const; | ||||
61 | void missingLanguagesChanged() const; | ||||
62 | | ||||
63 | private: | ||||
64 | QString languageCodeToName(const QString& languageCode) const; | ||||
65 | | ||||
66 | KConfigGroup m_config; | ||||
67 | | ||||
68 | QStringList m_languages; | ||||
69 | | ||||
70 | QSet<QString> m_installedLanguages; | ||||
71 | | ||||
72 | QStringList m_selectedLanguages; | ||||
73 | QStringList m_missingLanguages; | ||||
74 | }; | ||||
75 | | ||||
76 | #endif |