Purpose

JobView.qml
1/*
2 SPDX-FileCopyrightText: 2020 Nicolas Fella <nicolas.fella@gmx.de>
3 SPDX-License-Identifier: LGPL-2.1-or-later
4*/
5
6import QtQuick
7import QtQuick.Controls
8import QtQuick.Layouts
9
10import org.kde.purpose
11import org.kde.kirigami as Kirigami
12
13Item {
14
15 property alias model: jobController.model
16 property alias index: jobController.index
17
18 readonly property alias state: jobController.state
19 readonly property alias job: jobController.job
20
21 implicitHeight: mainLoader.implicitHeight
22
23 function start() {
24 jobController.configure()
25 }
26
27 PurposeJobController {
28 id: jobController
29 }
30
31 Loader {
32 id: mainLoader
33 anchors.fill: parent
34
35 sourceComponent: {
36 switch (jobController.state) {
37 case PurposeJobController.Configuring:
38 return configuring;
39 case PurposeJobController.Running:
40 return running;
41 default:
42 return null;
43 }
44 }
45 }
46
47 Component {
48 id: running
49
50 Item {
51 BusyIndicator {
52 running: true
53 anchors.centerIn: parent
54 }
55 }
56 }
57
58 Component {
59 id: configuring
60
61 ColumnLayout {
62 Loader {
63 id: configLoader
64
65 Layout.leftMargin: Kirigami.Units.largeSpacing
66 Layout.rightMargin: Kirigami.Units.largeSpacing
67 Layout.topMargin: Kirigami.Units.largeSpacing
68
69 Layout.fillHeight: true
70 Layout.fillWidth: true
71
72 Component.onCompleted: setSource(jobController.configuration.configSourceCode, jobController.configuration.data)
73
74 onItemChanged: {
75 var initialData = jobController.configuration.data;
76 for (var i in jobController.configuration.neededArguments) {
77 var arg = jobController.configuration.neededArguments[i];
78 if (arg in configLoader.item) {
79 item[arg + "Changed"].connect(dataHasChanged);
80 initialData[arg] = item[arg];
81 } else {
82 console.warn("property not found", arg);
83 }
84 }
85 jobController.configuration.data = initialData;
86 }
87
88 function dataHasChanged() {
89 var jobData = jobController.configuration.data;
90 for (var i in jobController.configuration.neededArguments) {
91 var arg = jobController.configuration.neededArguments[i];
92 if (arg in configLoader.item) {
93 jobData[arg] = configLoader.item[arg];
94 } else
95 console.warn("property not found", arg);
96 }
97 jobController.configuration.data = jobData;
98 }
99 }
100
101 Label {
102 textFormat: Text.PlainText
103 Layout.fillWidth: true
104 Layout.fillHeight: true
105 horizontalAlignment: Text.AlignHCenter
106 verticalAlignment: Text.AlignVCenter
107 visible: configLoader.status === Loader.Error
108 wrapMode: Text.WordWrap
109 text: configLoader.status === Loader.Error
110 ? i18nd("libpurpose6_quick", "Failed to load the configuration page for this action:\n\n%1", configLoader.sourceComponent.errorString())
111 : ""
112 }
113
114 // Not using a DialogButtonBox because it doesn't let us customize
115 // the buttons and conditionally disable any of them, which we want
116 RowLayout {
117 Layout.leftMargin: Kirigami.Units.largeSpacing
118 Layout.rightMargin: Kirigami.Units.largeSpacing
119 Layout.bottomMargin: Kirigami.Units.largeSpacing
120 Layout.alignment: Qt.AlignRight
121
122 Button {
123 text: i18nd("libpurpose6_quick", "Send")
124 icon.name: "document-send"
125 enabled: jobController.configuration
126 && jobController.configuration.isReady
127 onClicked: jobController.startJob()
128 }
129
130 Button {
131 text: i18nd("libpurpose6_quick", "Cancel")
132 icon.name: "dialog-cancel"
133 onClicked: jobController.cancel()
134 }
135 }
136 }
137 }
138}
QString i18nd(const char *domain, const char *text, const TYPE &arg...)
QString name(StandardAction id)
KGuiItem cancel()
AlignRight
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:09:06 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.