Changeset View
Changeset View
Standalone View
Standalone View
kcms/translations/package/contents/ui/main.qml
Show All 15 Lines | |||||
16 | * along with this library; see the file COPYING.LIB. If not, write to | 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, | 17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | * Boston, MA 02110-1301, USA. | 18 | * Boston, MA 02110-1301, USA. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | import QtQuick 2.1 | 21 | import QtQuick 2.1 | ||
22 | import QtQuick.Layouts 1.1 | 22 | import QtQuick.Layouts 1.1 | ||
23 | import QtQuick.Controls 2.3 as QtControls | 23 | import QtQuick.Controls 2.3 as QtControls | ||
24 | import org.kde.kirigami 2.4 as Kirigami | 24 | import org.kde.kirigami 2.5 as Kirigami | ||
25 | import org.kde.plasma.core 2.1 as PlasmaCore | 25 | import org.kde.plasma.core 2.1 as PlasmaCore | ||
26 | import org.kde.kcm 1.2 | 26 | import org.kde.kcm 1.2 | ||
27 | 27 | | |||
28 | ScrollViewKCM { | 28 | ScrollViewKCM { | ||
29 | id: root | 29 | id: root | ||
30 | 30 | | |||
31 | ConfigModule.quickHelp: i18n("Language") | 31 | ConfigModule.quickHelp: i18n("Language") | ||
32 | 32 | | |||
33 | PlasmaCore.SortFilterModel { | 33 | Component { | ||
34 | id: availableLanguagesModel | 34 | id: addLanguageItemComponent | ||
35 | 35 | | |||
36 | sourceModel: kcm.translationsModel | 36 | Kirigami.BasicListItem { | ||
37 | id: languageItem | ||||
37 | 38 | | |||
38 | filterRole: "IsSelected" | | |||
39 | filterCallback: function(source_row, value) { return !value; } | | |||
40 | | ||||
41 | sortRole: "display" | | |||
42 | } | | |||
43 | | ||||
44 | Kirigami.OverlaySheet { | | |||
45 | id: addLanguagesSheet | | |||
46 | | ||||
47 | parent: root.parent | | |||
48 | | ||||
49 | topPadding: 0 | | |||
50 | leftPadding: 0 | | |||
51 | rightPadding: 0 | | |||
52 | bottomPadding: 0 | | |||
53 | | ||||
54 | header: Kirigami.Heading { text: i18nc("@title:window", "Add Languages") } | | |||
55 | | ||||
56 | property var selectedLanguages: [] | | |||
57 | | ||||
58 | onSheetOpenChanged: selectedLanguages = [] | | |||
59 | | ||||
60 | ListView { | | |||
61 | implicitWidth: 18 * Kirigami.Units.gridUnit | | |||
62 | | ||||
63 | model: availableLanguagesModel | | |||
64 | | ||||
65 | delegate: Kirigami.BasicListItem { | | |||
66 | property string languageCode: model.LanguageCode | 39 | property string languageCode: model.LanguageCode | ||
67 | 40 | | |||
68 | reserveSpaceForIcon: false | 41 | reserveSpaceForIcon: false | ||
69 | 42 | | |||
70 | label: model.display | 43 | label: model.display | ||
71 | 44 | | |||
72 | checkable: true | 45 | checkable: true | ||
73 | onCheckedChanged: { | 46 | onCheckedChanged: { | ||
Show All 10 Lines | 54 | } else { | |||
84 | // There's no property change notification for pushing to an array | 57 | // There's no property change notification for pushing to an array | ||
85 | // in a var prop, so we can't bind selectedLanguages.length to | 58 | // in a var prop, so we can't bind selectedLanguages.length to | ||
86 | // addLanguagesButton.enabled. | 59 | // addLanguagesButton.enabled. | ||
87 | if (!addLanguagesSheet.selectedLanguages.length) { | 60 | if (!addLanguagesSheet.selectedLanguages.length) { | ||
88 | addLanguagesButton.enabled = false; | 61 | addLanguagesButton.enabled = false; | ||
89 | } | 62 | } | ||
90 | } | 63 | } | ||
91 | } | 64 | } | ||
65 | | ||||
66 | data: [Connections { | ||||
67 | target: addLanguagesSheet | ||||
68 | | ||||
69 | onSheetOpenChanged: languageItem.checked = false | ||||
70 | }] | ||||
71 | } | ||||
72 | } | ||||
73 | | ||||
74 | Kirigami.OverlaySheet { | ||||
75 | id: addLanguagesSheet | ||||
76 | | ||||
77 | parent: root.parent | ||||
mart: this explicit reparenting shouldn't be necessary (and breaks in my branch for multi level kcms) | |||||
I've told you a few times now that it's been necessary for me so far, since the sheet doesn't appear or in bizarre locations otherwise. Did you test? hein: I've told you a few times now that it's been necessary for me so far, since the sheet doesn't… | |||||
78 | | ||||
79 | topPadding: 0 | ||||
80 | leftPadding: 0 | ||||
81 | rightPadding: 0 | ||||
82 | bottomPadding: 0 | ||||
83 | | ||||
84 | header: Kirigami.Heading { text: i18nc("@title:window", "Add Languages") } | ||||
85 | | ||||
86 | property var selectedLanguages: [] | ||||
87 | | ||||
88 | onSheetOpenChanged: selectedLanguages = [] | ||||
89 | | ||||
90 | ListView { | ||||
91 | id: availableLanguagesList | ||||
92 | | ||||
93 | implicitWidth: 18 * Kirigami.Units.gridUnit | ||||
94 | | ||||
95 | model: kcm.availableTranslationsModel | ||||
96 | | ||||
97 | delegate: Kirigami.DelegateRecycler { | ||||
98 | width: parent.width | ||||
mart: is this width: necessary? | |||||
I added it because you told me several times that it's necessary now. You tell me? hein: I added it because you told me several times that it's necessary now. You tell me? | |||||
99 | | ||||
100 | sourceComponent: addLanguageItemComponent | ||||
92 | } | 101 | } | ||
93 | } | 102 | } | ||
94 | 103 | | |||
95 | footer: RowLayout { | 104 | footer: RowLayout { | ||
96 | QtControls.Button { | 105 | QtControls.Button { | ||
97 | id: addLanguagesButton | 106 | id: addLanguagesButton | ||
98 | 107 | | |||
99 | Layout.alignment: Qt.AlignHCenter | 108 | Layout.alignment: Qt.AlignHCenter | ||
100 | 109 | | |||
101 | text: i18nc("@action:button", "Add") | 110 | text: i18nc("@action:button", "Add") | ||
102 | 111 | | |||
103 | enabled: false | 112 | enabled: false | ||
104 | 113 | | |||
105 | onClicked: { | 114 | onClicked: { | ||
106 | var langs = kcm.translationsModel.selectedLanguages.slice(); | 115 | var langs = kcm.selectedTranslationsModel.selectedLanguages.slice(); | ||
107 | addLanguagesSheet.selectedLanguages.sort().forEach(function(index) { | 116 | addLanguagesSheet.selectedLanguages.sort().forEach(function(index) { | ||
108 | langs.push(availableLanguagesModel.get(index).LanguageCode); | 117 | langs.push(kcm.availableTranslationsModel.langCodeAt(index)); | ||
109 | }); | 118 | }); | ||
110 | 119 | | |||
111 | kcm.translationsModel.selectedLanguages = langs; | 120 | kcm.selectedTranslationsModel.selectedLanguages = langs; | ||
112 | 121 | | |||
113 | addLanguagesSheet.sheetOpen = false; | 122 | addLanguagesSheet.sheetOpen = false; | ||
114 | } | 123 | } | ||
115 | } | 124 | } | ||
116 | } | 125 | } | ||
117 | } | 126 | } | ||
118 | 127 | | |||
119 | header: ColumnLayout { | 128 | header: ColumnLayout { | ||
120 | id: messagesLayout | 129 | id: messagesLayout | ||
121 | 130 | | |||
122 | spacing: Kirigami.Units.largeSpacing | 131 | spacing: Kirigami.Units.largeSpacing | ||
123 | 132 | | |||
124 | Kirigami.InlineMessage { | 133 | Kirigami.InlineMessage { | ||
125 | Layout.fillWidth: true | 134 | Layout.fillWidth: true | ||
126 | 135 | | |||
127 | type: Kirigami.MessageType.Information | 136 | type: Kirigami.MessageType.Information | ||
128 | 137 | | |||
129 | text: i18nc("@info", "There are no languages available on this system.") | 138 | text: i18nc("@info", "There are no languages available on this system.") | ||
130 | 139 | | |||
131 | visible: !availableLanguagesModel.count | 140 | visible: !availableLanguagesList.count | ||
132 | } | 141 | } | ||
133 | 142 | | |||
134 | Kirigami.InlineMessage { | 143 | Kirigami.InlineMessage { | ||
135 | Layout.fillWidth: true | 144 | Layout.fillWidth: true | ||
136 | 145 | | |||
137 | type: kcm.everSaved ? Kirigami.MessageType.Positive : Kirigami.MessageType.Information | 146 | type: kcm.everSaved ? Kirigami.MessageType.Positive : Kirigami.MessageType.Information | ||
138 | 147 | | |||
139 | text: (kcm.everSaved ? i18nc("@info", "Your changes will take effect the next time you log in.") | 148 | text: (kcm.everSaved ? i18nc("@info", "Your changes will take effect the next time you log in.") | ||
140 | : i18nc("@info", "There are currently no preferred languages configured.")) | 149 | : i18nc("@info", "There are currently no preferred languages configured.")) | ||
141 | 150 | | |||
142 | visible: !languagesList.count || kcm.everSaved | 151 | visible: !languagesList.count || kcm.everSaved | ||
143 | } | 152 | } | ||
144 | 153 | | |||
145 | Kirigami.InlineMessage { | 154 | Kirigami.InlineMessage { | ||
146 | Layout.fillWidth: true | 155 | Layout.fillWidth: true | ||
147 | 156 | | |||
148 | type: Kirigami.MessageType.Error | 157 | type: Kirigami.MessageType.Error | ||
149 | 158 | | |||
150 | text: i18ncp("@info %2 is the language code", | 159 | text: i18ncp("@info %2 is the language code", | ||
151 | "The translation files for the language with the code '%2' could not be found. The language will be removed from your configuration. If you want to add it back, please install the localization files for it and add the language again.", | 160 | "The translation files for the language with the code '%2' could not be found. The language will be removed from your configuration. If you want to add it back, please install the localization files for it and add the language again.", | ||
152 | "The translation files for the languages with the codes '%2' could not be found. These languages will be removed from your configuration. If you want to add them back, please install the localization files for it and the languages again.", | 161 | "The translation files for the languages with the codes '%2' could not be found. These languages will be removed from your configuration. If you want to add them back, please install the localization files for it and the languages again.", | ||
153 | kcm.translationsModel.missingLanguages.length, | 162 | kcm.selectedTranslationsModel.missingLanguages.length, | ||
154 | kcm.translationsModel.missingLanguages.join("', '")) | 163 | kcm.selectedTranslationsModel.missingLanguages.join("', '")) | ||
155 | 164 | | |||
156 | visible: kcm.translationsModel.missingLanguages.length | 165 | visible: kcm.selectedTranslationsModel.missingLanguages.length | ||
157 | } | 166 | } | ||
158 | 167 | | |||
159 | QtControls.Label { | 168 | QtControls.Label { | ||
160 | Layout.fillWidth: true | 169 | Layout.fillWidth: true | ||
161 | 170 | | |||
162 | visible: languagesList.count | 171 | visible: languagesList.count | ||
163 | 172 | | |||
164 | text: i18n("The language at the top of this list is the one you want to see and use most often.") | 173 | text: i18n("The language at the top of this list is the one you want to see and use most often.") | ||
165 | } | 174 | } | ||
166 | } | 175 | } | ||
167 | 176 | | |||
168 | view: ListView { | 177 | Component { | ||
169 | id: languagesList | 178 | id: languagesListItemComponent | ||
170 | | ||||
171 | model: PlasmaCore.SortFilterModel { | | |||
172 | sourceModel: kcm.translationsModel | | |||
173 | 179 | | |||
174 | filterRole: "IsSelected" | 180 | Kirigami.SwipeListItem { | ||
175 | filterCallback: function(source_row, value) { return value; } | | |||
176 | | ||||
177 | sortRole: "SelectedPriority" | | |||
178 | } | | |||
179 | | ||||
180 | delegate: Kirigami.SwipeListItem { | | |||
181 | id: listItem | 181 | id: listItem | ||
182 | 182 | | |||
183 | width: ListView.view.width | | |||
184 | | ||||
185 | contentItem: RowLayout { | 183 | contentItem: RowLayout { | ||
186 | width: implicitWidth | 184 | width: implicitWidth | ||
mart: this shouldn't be necessary | |||||
hein: I'll remove it soon. | |||||
187 | height: Math.max(implicitHeight, Kirigami.Units.iconSizes.smallMedium) | | |||
188 | 185 | | |||
189 | anchors.verticalCenter: parent.verticalCenter | 186 | Kirigami.ListItemDragHandle { | ||
187 | listItem: listItem | ||||
188 | listView: languagesList | ||||
189 | onMoveRequested: kcm.selectedTranslationsModel.move(oldIndex, newIndex) | ||||
190 | } | ||||
190 | 191 | | |||
191 | Kirigami.Icon { | 192 | Kirigami.Icon { | ||
192 | visible: model.IsMissing | 193 | visible: model.IsMissing | ||
193 | 194 | | |||
194 | Layout.alignment: Qt.AlignVCenter | 195 | Layout.alignment: Qt.AlignVCenter | ||
195 | 196 | | |||
196 | width: Kirigami.Units.iconSizes.smallMedium | 197 | width: Kirigami.Units.iconSizes.smallMedium | ||
197 | height: width | 198 | height: width | ||
Show All 15 Lines | |||||
213 | } | 214 | } | ||
214 | } | 215 | } | ||
215 | 216 | | |||
216 | actions: [ | 217 | actions: [ | ||
217 | Kirigami.Action { | 218 | Kirigami.Action { | ||
218 | enabled: !model.IsMissing && index > 0 | 219 | enabled: !model.IsMissing && index > 0 | ||
219 | iconName: "go-top" | 220 | iconName: "go-top" | ||
220 | tooltip: i18nc("@info:tooltip", "Promote to default") | 221 | tooltip: i18nc("@info:tooltip", "Promote to default") | ||
221 | onTriggered: kcm.translationsModel.moveSelectedLanguage(index, 0) | 222 | onTriggered: kcm.selectedTranslationsModel.move(index, 0) | ||
222 | }, | | |||
223 | Kirigami.Action { | | |||
224 | enabled: !model.IsMissing && index > 0 | | |||
225 | iconName: "go-up" | | |||
226 | tooltip: i18nc("@info:tooltip", "Move up") | | |||
227 | onTriggered: kcm.translationsModel.moveSelectedLanguage(index, index - 1) | | |||
228 | }, | | |||
229 | Kirigami.Action { | | |||
230 | enabled: !model.IsMissing && index < (languagesList.count - 1) | | |||
231 | iconName: "go-down" | | |||
232 | tooltip: i18nc("@info:tooltip", "Move down") | | |||
233 | onTriggered: kcm.translationsModel.moveSelectedLanguage(index, index + 1) | | |||
234 | }, | 223 | }, | ||
235 | Kirigami.Action { | 224 | Kirigami.Action { | ||
236 | enabled: !model.IsMissing | 225 | enabled: !model.IsMissing | ||
237 | iconName: "list-remove" | 226 | iconName: "list-remove" | ||
238 | tooltip: i18nc("@info:tooltip", "Remove") | 227 | tooltip: i18nc("@info:tooltip", "Remove") | ||
239 | onTriggered: kcm.translationsModel.removeSelectedLanguage(model.LanguageCode) | 228 | onTriggered: kcm.selectedTranslationsModel.remove(model.LanguageCode) | ||
240 | }] | 229 | }] | ||
241 | } | 230 | } | ||
242 | } | 231 | } | ||
243 | 232 | | |||
233 | view: ListView { | ||||
234 | id: languagesList | ||||
235 | | ||||
236 | model: kcm.selectedTranslationsModel | ||||
237 | | ||||
238 | delegate: Kirigami.DelegateRecycler { | ||||
239 | width: languagesList.width | ||||
240 | | ||||
241 | sourceComponent: languagesListItemComponent | ||||
242 | } | ||||
243 | } | ||||
244 | | ||||
244 | footer: RowLayout { | 245 | footer: RowLayout { | ||
245 | id: footerLayout | 246 | id: footerLayout | ||
246 | 247 | | |||
247 | QtControls.Button { | 248 | QtControls.Button { | ||
248 | Layout.alignment: Qt.AlignRight | 249 | Layout.alignment: Qt.AlignRight | ||
249 | 250 | | |||
250 | enabled: availableLanguagesModel.count | 251 | enabled: availableLanguagesList.count | ||
251 | 252 | | |||
252 | text: i18nc("@action:button", "Add languages...") | 253 | text: i18nc("@action:button", "Add languages...") | ||
253 | 254 | | |||
254 | onClicked: addLanguagesSheet.sheetOpen = !addLanguagesSheet.sheetOpen | 255 | onClicked: addLanguagesSheet.sheetOpen = !addLanguagesSheet.sheetOpen | ||
255 | 256 | | |||
256 | checkable: true | 257 | checkable: true | ||
257 | checked: addLanguagesSheet.sheetOpen | 258 | checked: addLanguagesSheet.sheetOpen | ||
258 | } | 259 | } | ||
259 | } | 260 | } | ||
260 | } | 261 | } | ||
261 | 262 | |
this explicit reparenting shouldn't be necessary (and breaks in my branch for multi level kcms)