Purpose

AlternativesView.qml
1/*
2 SPDX-FileCopyrightText: 2014 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
3
4 SPDX-License-Identifier: LGPL-2.1-or-later
5*/
6
7import QtQuick 2.2
8import QtQuick.Layouts 1.1
9import QtQuick.Controls 2.2
10import org.kde.purpose 1.0
11
12StackView {
13 id: stack
14 focus: true
15
16 implicitHeight: currentItem.implicitHeight
17
18 property bool running: false
19 property alias pluginType: altsModel.pluginType
20 property alias inputData: altsModel.inputData
21 property Component highlight
22 property Component header
23 property Component footer
24 property variant verticalLayoutDirection: ListView.TopToBottom
25 property Component delegate: Component {
26 RowLayout {
27 width: ListView.view.width
28 Label {
29 Layout.fillWidth: true
30 text: display
31 elide: Text.ElideRight
32 }
33 Button {
34 text: i18nd("libpurpose6_quick", "Use")
35 onClicked: createJob(index);
36 }
37 Keys.onReturnPressed: createJob(index)
38 Keys.onEnterPressed: createJob(index)
39 }
40 }
41
42 /**
43 * Signals when the job finishes, reports the
44 * @p error code and a text @p message.
45 *
46 * @p output will specify the output offered by the job
47 */
48 signal finished(var output, int error, string message)
49
50 PurposeAlternativesModel {
51 id: altsModel
52 }
53
54 /**
55 * Adopts the job at the @p index.
56 */
57 function createJob(index) {
58 stack.push(jobComponent, {index: index})
59 }
60
61 /**
62 * Clears and returns back to the initial view.
63 */
64 function reset() {
65 for(; stack.depth>1; stack.pop())
66 {}
67 }
68
69 initialItem: ListView {
70 ScrollBar.vertical: ScrollBar {}
71 focus: true
72 model: altsModel
73
74 implicitHeight: contentHeight
75
76 verticalLayoutDirection: stack.verticalLayoutDirection
77 delegate: stack.delegate
78 highlight: stack.highlight
79 footer: stack.footer
80 header: stack.header
81 }
82
83 Component {
84 id: jobComponent
85
86 JobView {
87 id: jobView
88 model: altsModel
89
90 onStateChanged: {
91 if (state === PurposeJobController.Finished || state === PurposeJobController.Error) {
92 stack.finished(jobView.job.output, jobView.job.error, jobView.job.errorString);
93 } else if (state === PurposeJobController.Cancelled) {
94 stack.pop();
95 }
96 }
97
98 Component.onCompleted: start()
99 }
100 }
101}
Q_SCRIPTABLE Q_NOREPLY void start()
KGuiItem reset()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:14:05 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.