KNewStuff

Page.qml
1 /*
2  SPDX-FileCopyrightText: 2019 Dan Leinir Turthra Jensen <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 
15 import QtQuick 2.11
16 import QtQuick.Controls 2.11 as QtControls
17 import QtQuick.Layouts 1.11 as QtLayouts
18 import QtGraphicalEffects 1.11 as QtEffects
19 
20 import org.kde.kcm 1.2 as KCM
21 import org.kde.kirigami 2.12 as Kirigami
22 
23 import org.kde.newstuff 1.62 as NewStuff
24 
25 import "private" as Private
26 import "private/entrygriddelegates" as EntryGridDelegates
27 
28 KCM.GridViewKCM {
29  id: root;
36  property alias configFile: newStuffEngine.configFile;
37  readonly property alias engine: newStuffEngine;
38 
43  signal message(string message);
49  signal idleMessage(string message);
55  signal busyMessage(string message);
60  signal errorMessage(string message);
61 
62  property string uninstallLabel: i18ndc("knewstuff5", "Request uninstallation of this item", "Uninstall");
63  property string useLabel: engine.engine.useLabel
64 
65  property int viewMode: Page.ViewMode.Tiles
66  enum ViewMode {
67  Tiles,
68  Icons,
69  Preview
70  }
71 
72  // Otherwise the first item will be focused, see BUG: 424894
73  Component.onCompleted: {
74  view.currentIndex = -1
75  }
76 
77  title: newStuffEngine.name
78  NewStuff.Engine {
79  id: newStuffEngine;
80  property string statusMessage;
81  onMessage: {
82  root.message(message);
83  statusMessage = message;
84  }
85  onIdleMessage: {
86  root.idleMessage(message);
87  statusMessage = message;
88  }
89  onBusyMessage: {
90  root.busyMessage(message);
91  statusMessage = message;
92  }
93  onErrorMessage: {
94  root.errorMessage(message);
95  statusMessage = message;
96  }
97  }
98  NewStuff.QuestionAsker {}
99  Private.ErrorDisplayer { engine: newStuffEngine; active: root.isCurrentPage; }
100 
101  titleDelegate: QtLayouts.RowLayout {
102  QtLayouts.Layout.fillWidth: true
103  Kirigami.Heading {
104  id: title
105  level: 1
106 
107  QtLayouts.Layout.fillWidth: true;
108  opacity: root.isCurrentPage ? 1 : 0.4
109  maximumLineCount: 1
110  elide: Text.ElideRight
111  text: root.title
112  }
113  QtControls.ButtonGroup {
114  id: displayModeGroup
115  buttons: [displayModeTiles, displayModeIcons]
116  }
117  QtControls.ToolButton {
118  id: displayModeTiles
119  icon.name: "view-list-details"
120  onClicked: { root.viewMode = Page.ViewMode.Tiles; }
121  checked: root.viewMode == Page.ViewMode.Tiles
122  QtControls.ToolTip {
123  text: i18nd("knewstuff5", "Tiles view mode")
124  }
125  }
126  QtControls.ToolButton {
127  id: displayModeIcons
128  icon.name: "view-list-icons"
129  onClicked: { root.viewMode = Page.ViewMode.Icons; }
130  checked: root.viewMode == Page.ViewMode.Icons
131  QtControls.ToolTip {
132  text: i18nd("knewstuff5", "Icons view mode")
133  }
134  }
135  QtControls.ToolButton {
136  id: displayPreview
137  icon.name: "view-preview"
138  onClicked: { root.viewMode = Page.ViewMode.Preview; }
139  checked: root.viewMode == Page.ViewMode.Preview
140  QtControls.ToolTip {
141  text: i18nd("knewstuff5", "Preview view mode")
142  }
143  }
144  Kirigami.ActionTextField {
145  id: searchField
146  placeholderText: i18nd("knewstuff5", "Search...")
147  focusSequence: "Ctrl+F"
148  rightActions: [
149  Kirigami.Action {
150  iconName: "edit-clear"
151  visible: searchField.text !== ""
152  onTriggered: {
153  searchField.text = "";
154  searchField.accepted();
155  }
156  }
157  ]
158  onAccepted: {
159  newStuffEngine.searchTerm = searchField.text;
160  }
161  enabled: filterCombo.currentIndex === 0
162  }
163  }
164 
165  footer: QtLayouts.RowLayout {
166  QtControls.Label {
167  text: i18n("Show:")
168  }
169  QtControls.ComboBox {
170  id: categoriesCombo
171  QtLayouts.Layout.fillWidth: true
172  // Only show this combobox when there are multiple categories
173  visible: count > 2
174  model: newStuffEngine.categories
175  textRole: "displayName"
176  onCurrentIndexChanged: {
177  newStuffEngine.categoriesFilter = model.data(model.index(currentIndex, 0), NewStuff.CategoriesModel.NameRole);
178  }
179  }
180  QtControls.ComboBox {
181  id: filterCombo
182  QtLayouts.Layout.fillWidth: true
183  model: ListModel {}
184  Component.onCompleted: {
185  filterCombo.model.append({ text: i18ndc("knewstuff5", "List option which will set the filter to show everything", "Everything") });
186  filterCombo.model.append({ text: i18ndc("knewstuff5", "List option which will set the filter so only installed items are shown", "Installed Only") });
187  filterCombo.model.append({ text: i18ndc("knewstuff5", "List option which will set the filter so only installed items with updates available are shown", "Updateable Only") });
188  filterCombo.currentIndex = newStuffEngine.filter;
189  }
190  onCurrentIndexChanged: {
191  newStuffEngine.filter = currentIndex;
192  }
193  }
194  QtControls.ComboBox {
195  id: sortCombo
196  QtLayouts.Layout.fillWidth: true
197  model: ListModel { }
198  Component.onCompleted: {
199  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") });
200  sortCombo.model.append({ text: i18ndc("knewstuff5", "List option which will set the sort order to be alphabetical based on the name", "A-Z") });
201  sortCombo.model.append({ text: i18ndc("knewstuff5", "List option which will set the sort order to based on user ratings", "Highest rated first") });
202  sortCombo.model.append({ text: i18ndc("knewstuff5", "List option which will set the sort order to based on number of downloads", "Most downloaded first") });
203  sortCombo.currentIndex = newStuffEngine.sortOrder;
204  }
205  onCurrentIndexChanged: {
206  newStuffEngine.sortOrder = currentIndex;
207  }
208  }
209  }
210 
211  view.model: NewStuff.ItemsModel {
212  id: newStuffModel;
213  engine: newStuffEngine;
214  }
215  NewStuff.DownloadItemsSheet {
216  id: downloadItemsSheet
217  onItemPicked: {
218  newStuffModel.installItem(entryId, downloadItemId);
219  }
220  }
221 
222  view.implicitCellWidth: root.viewMode == Page.ViewMode.Tiles ? Kirigami.Units.gridUnit * 30 : (root.viewMode == Page.ViewMode.Preview ? Kirigami.Units.gridUnit * 25 : Kirigami.Units.gridUnit * 10)
223  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)
224  view.delegate: root.viewMode == Page.ViewMode.Tiles ? tileDelegate : (root.viewMode == Page.ViewMode.Preview ? bigPreviewDelegate : thumbDelegate)
225 
226  Component {
227  id: bigPreviewDelegate
228  EntryGridDelegates.BigPreviewDelegate { }
229  }
230  Component {
231  id: tileDelegate
232  EntryGridDelegates.TileDelegate {
233  useLabel: root.useLabel
234  uninstallLabel: root.uninstallLabel
235  }
236  }
237  Component {
238  id: thumbDelegate
239  EntryGridDelegates.ThumbDelegate {
240  useLabel: root.useLabel
241  uninstallLabel: root.uninstallLabel
242  }
243  }
244 
245  Component {
246  id: detailsPage;
247  NewStuff.EntryDetails { }
248  }
249 
250  Item {
251  anchors.fill: parent
252  opacity: (newStuffEngine.isLoading || newStuffModel.isLoadingData) ? 1 : 0
253  Behavior on opacity { NumberAnimation { duration: Kirigami.Units.longDuration; } }
254  visible: opacity > 0
255  Rectangle {
256  anchors.fill: parent
257  color: Kirigami.Theme.backgroundColor
258  opacity: 0.7
259  }
260  QtControls.BusyIndicator {
261  anchors {
262  horizontalCenter: parent.horizontalCenter
263  bottom: parent.verticalCenter
264  bottomMargin: Kirigami.Units.largeSpacing
265  }
266  running: newStuffEngine.isLoading || newStuffModel.isLoadingData
267  }
268  QtControls.Label {
269  anchors {
270  top: parent.verticalCenter
271  left: parent.left
272  right: parent.right
273  margins: Kirigami.Units.largeSpacing
274  }
275  horizontalAlignment: Text.AlignHCenter
276  text: newStuffEngine.isLoading ? newStuffEngine.statusMessage :
277  i18ndc("knewstuff5", "A text shown beside a busy indicator suggesting that data is being fetched", "Loading more...")
278  }
279  }
280  Kirigami.PlaceholderMessage {
281  anchors.centerIn: parent
282  anchors.left: parent.left
283  anchors.right: parent.right
284  anchors.margins: Kirigami.Units.largeSpacing
285 
286  visible: newStuffEngine.isLoading === false && newStuffModel.isLoadingData === false && view.count === 0
287 
288  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")
289  }
290 }
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:22
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-2021 The KDE developers.
Generated on Mon Jan 18 2021 22:43:50 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.