KNewStuff

Page.qml
1 /*
2  * Copyright (C) 2019 Dan Leinir Turthra Jensen <[email protected]>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) version 3, or any
8  * later version accepted by the membership of KDE e.V. (or its
9  * successor approved by the membership of KDE e.V.), which shall
10  * act as a proxy defined in Section 6 of version 3 of the license.
11  *
12  * This library 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 GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
30 import QtQuick 2.11
31 import QtQuick.Controls 2.11 as QtControls
32 import QtQuick.Layouts 1.11 as QtLayouts
33 import QtGraphicalEffects 1.11 as QtEffects
34 
35 import org.kde.kcm 1.2 as KCM
36 import org.kde.kirigami 2.12 as Kirigami
37 
38 import org.kde.newstuff 1.62 as NewStuff
39 
40 import "private" as Private
41 import "private/entrygriddelegates" as EntryGridDelegates
42 
43 KCM.GridViewKCM {
44  id: root;
51  property alias configFile: newStuffEngine.configFile;
52  readonly property alias engine: newStuffEngine;
53 
58  signal message(string message);
64  signal idleMessage(string message);
70  signal busyMessage(string message);
75  signal errorMessage(string message);
76 
77  property string uninstallLabel: i18ndc("knewstuff5", "Request uninstallation of this item", "Uninstall");
78  property string useLabel: i18ndc("knewstuff5", "If a knsrc file defines an adoption command, the option to run this command and 'use' an item becomes available. This is the text for an action to do so.", "Use");
79 
80  property int viewMode: Page.ViewMode.Tiles
81  enum ViewMode {
82  Tiles,
83  Icons,
84  Preview
85  }
86 
87  title: newStuffEngine.name
88  NewStuff.Engine {
89  id: newStuffEngine;
90  property string statusMessage;
91  onMessage: {
92  root.message(message);
93  statusMessage = message;
94  }
95  onIdleMessage: {
96  root.idleMessage(message);
97  statusMessage = message;
98  }
99  onBusyMessage: {
100  root.busyMessage(message);
101  statusMessage = message;
102  }
103  onErrorMessage: {
104  root.errorMessage(message);
105  statusMessage = message;
106  }
107  }
108  NewStuff.QuestionAsker {}
109  Private.ErrorDisplayer { engine: newStuffEngine; active: root.isCurrentPage; }
110 
111  titleDelegate: QtLayouts.RowLayout {
112  QtLayouts.Layout.fillWidth: true
113  Kirigami.Heading {
114  id: title
115  level: 1
116 
117  QtLayouts.Layout.fillWidth: true;
118  opacity: root.isCurrentPage ? 1 : 0.4
119  maximumLineCount: 1
120  elide: Text.ElideRight
121  text: root.title
122  }
123  QtControls.ButtonGroup {
124  id: displayModeGroup
125  buttons: [displayModeTiles, displayModeIcons]
126  }
127  QtControls.ToolButton {
128  id: displayModeTiles
129  icon.name: "view-list-details"
130  onClicked: { root.viewMode = Page.ViewMode.Tiles; }
131  checked: root.viewMode == Page.ViewMode.Tiles
132  QtControls.ToolTip {
133  text: i18nd("knewstuff5", "Tiles view mode")
134  }
135  }
136  QtControls.ToolButton {
137  id: displayModeIcons
138  icon.name: "view-list-icons"
139  onClicked: { root.viewMode = Page.ViewMode.Icons; }
140  checked: root.viewMode == Page.ViewMode.Icons
141  QtControls.ToolTip {
142  text: i18nd("knewstuff5", "Icons view mode")
143  }
144  }
145  QtControls.ToolButton {
146  id: displayPreview
147  icon.name: "view-preview"
148  onClicked: { root.viewMode = Page.ViewMode.Preview; }
149  checked: root.viewMode == Page.ViewMode.Preview
150  QtControls.ToolTip {
151  text: i18nd("knewstuff5", "Preview view mode")
152  }
153  }
154  Kirigami.ActionTextField {
155  id: searchField
156  placeholderText: i18nd("knewstuff5", "Search...")
157  focusSequence: "Ctrl+F"
158  rightActions: [
159  Kirigami.Action {
160  iconName: "edit-clear"
161  visible: searchField.text !== ""
162  onTriggered: {
163  searchField.text = "";
164  searchField.accepted();
165  }
166  }
167  ]
168  onAccepted: {
169  newStuffEngine.searchTerm = searchField.text;
170  }
171  }
172  }
173 
174  footer: QtLayouts.RowLayout {
175  QtControls.Label {
176  text: i18n("Show:")
177  }
178  QtControls.ComboBox {
179  id: categoriesCombo
180  QtLayouts.Layout.fillWidth: true
181  // Only show this combobox when there are multiple categories
182  visible: count > 2
183  model: newStuffEngine.categories
184  textRole: "displayName"
185  onCurrentIndexChanged: {
186  newStuffEngine.categoriesFilter = model.data(model.index(currentIndex, 0), NewStuff.CategoriesModel.NameRole);
187  }
188  }
189  QtControls.ComboBox {
190  id: filterCombo
191  QtLayouts.Layout.fillWidth: true
192  model: ListModel {}
193  Component.onCompleted: {
194  filterCombo.model.append({ text: i18ndc("knewstuff5", "List option which will set the filter to show everything", "Everything") });
195  filterCombo.model.append({ text: i18ndc("knewstuff5", "List option which will set the filter so only installed items are shown", "Installed Only") });
196  filterCombo.model.append({ text: i18ndc("knewstuff5", "List option which will set the filter so only installed items with updates available are shown", "Updateable Only") });
197  filterCombo.currentIndex = newStuffEngine.filter;
198  }
199  onCurrentIndexChanged: {
200  newStuffEngine.filter = currentIndex;
201  }
202  }
203  QtControls.ComboBox {
204  id: sortCombo
205  QtLayouts.Layout.fillWidth: true
206  model: ListModel { }
207  Component.onCompleted: {
208  sortCombo.model.append({ text: i18ndc("knewstuff5", "List option which will set the sort order to based on when items were most recently updated", "Most recent first") });
209  sortCombo.model.append({ text: i18ndc("knewstuff5", "List option which will set the sort order to be alphabetical based on the name", "A-Z") });
210  sortCombo.model.append({ text: i18ndc("knewstuff5", "List option which will set the sort order to based on user ratings", "Highest rated first") });
211  sortCombo.model.append({ text: i18ndc("knewstuff5", "List option which will set the sort order to based on number of downloads", "Most downloaded first") });
212  sortCombo.currentIndex = newStuffEngine.sortOrder;
213  }
214  onCurrentIndexChanged: {
215  newStuffEngine.sortOrder = currentIndex;
216  }
217  }
218  }
219 
220  view.model: NewStuff.ItemsModel {
221  id: newStuffModel;
222  engine: newStuffEngine;
223  }
224  NewStuff.DownloadItemsSheet {
225  id: downloadItemsSheet
226  onItemPicked: {
227  newStuffModel.installItem(entryId, downloadItemId);
228  }
229  }
230 
231  view.implicitCellWidth: root.viewMode == Page.ViewMode.Tiles ? Kirigami.Units.gridUnit * 30 : (root.viewMode == Page.ViewMode.Preview ? Kirigami.Units.gridUnit * 25 : Kirigami.Units.gridUnit * 10)
232  view.implicitCellHeight: root.viewMode == Page.ViewMode.Tiles ? Math.round(view.implicitCellWidth / 3) : (root.viewMode == Page.ViewMode.Preview ? Kirigami.Units.gridUnit * 25 : Math.round(view.implicitCellWidth / 1.6) + Kirigami.Units.gridUnit*2)
233  view.delegate: root.viewMode == Page.ViewMode.Tiles ? tileDelegate : (root.viewMode == Page.ViewMode.Preview ? bigPreviewDelegate : thumbDelegate)
234 
235  view.footer: Item {
236  width: GridView.view.width
237  height: GridView.view.count > 0 ? Kirigami.Units.gridUnit * 3 : GridView.view.height
238  Behavior on height { NumberAnimation { duration: Kirigami.Units.shortDuration; } }
239  visible: opacity > 0
240  opacity: newStuffModel.isLoadingData && !newStuffEngine.isLoading ? 1 : 0
241  Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration; } }
242  QtControls.BusyIndicator {
243  anchors {
244  top: parent.top
245  right: parent.horizontalCenter
246  bottom: parent.bottom
247  margins: Kirigami.Units.smallSpacing
248  }
249  width: Kirigami.Units.gridUnit * 3 - Kirigami.Units.smallSpacing * 2
250  running: parent.visible
251  QtControls.Label {
252  anchors {
253  top: parent.top
254  left: parent.right
255  leftMargin: Kirigami.Units.largeSpacing
256  bottom: parent.bottom
257  }
258  text: i18ndc("knewstuff5", "A text shown beside a busy indicator suggesting that data is being fetched", "Loading more...")
259  verticalAlignment: Text.AlignVCenter
260  }
261  }
262  }
263 
264  Component {
265  id: bigPreviewDelegate
266  EntryGridDelegates.BigPreviewDelegate { }
267  }
268  Component {
269  id: tileDelegate
270  EntryGridDelegates.TileDelegate {
271  useLabel: root.useLabel
272  uninstallLabel: root.uninstallLabel
273  }
274  }
275  Component {
276  id: thumbDelegate
277  EntryGridDelegates.ThumbDelegate {
278  useLabel: root.useLabel
279  uninstallLabel: root.uninstallLabel
280  }
281  }
282 
283  Component {
284  id: detailsPage;
285  NewStuff.EntryDetails { }
286  }
287 
288  Item {
289  anchors.fill: parent
290  opacity: newStuffEngine.isLoading ? 1 : 0
291  Behavior on opacity { NumberAnimation { duration: Kirigami.Units.longDuration; } }
292  visible: opacity > 0
293  Rectangle {
294  anchors.fill: parent
295  color: Kirigami.Theme.backgroundColor
296  opacity: 0.7
297  }
298  QtControls.BusyIndicator {
299  anchors {
300  horizontalCenter: parent.horizontalCenter
301  bottom: parent.verticalCenter
302  bottomMargin: Kirigami.Units.largeSpacing
303  }
304  running: newStuffEngine.isLoading
305  }
306  QtControls.Label {
307  anchors {
308  top: parent.verticalCenter
309  left: parent.left
310  right: parent.right
311  margins: Kirigami.Units.largeSpacing
312  }
313  horizontalAlignment: Text.AlignHCenter
314  text: newStuffEngine.statusMessage
315  }
316  }
317  Kirigami.PlaceholderMessage {
318  anchors.centerIn: parent
319  anchors.left: parent.left
320  anchors.right: parent.right
321  anchors.margins: Kirigami.Units.largeSpacing
322 
323  visible: newStuffEngine.isLoading === false && newStuffModel.isLoadingData === false && view.count === 0
324 
325  text: i18ndc("knewstuff5", "A message shown when there are no entries in the list, and when it is not trying to load anything", "There is no hot new stuff to get here")
326  }
327 }
void message(string message)
Any generic message from the NewStuff.Engine.
QString i18ndc(const char *domain, const char *context, const char *text, const TYPE &arg...)
QTextStream & left(QTextStream &s)
KCALUTILS_EXPORT QString errorMessage(const KCalendarCore::Exception &exception)
A Kirigami.Page component used for managing KNS entries.
Definition: Page.qml:37
QString i18n(const char *text, const TYPE &arg...)
QTextStream & right(QTextStream &s)
QString i18nd(const char *domain, const char *text, const TYPE &arg...)
QChar * data()
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun Aug 9 2020 22:43:40 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.