Warning, /frameworks/purpose/src/quick/AlternativesView.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2014 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-or-later
0005 */
0006 
0007 import QtQuick 2.2
0008 import QtQuick.Layouts 1.1
0009 import QtQuick.Controls 2.2
0010 import org.kde.purpose 1.0
0011 
0012 StackView {
0013     id: stack
0014     focus: true
0015 
0016     implicitHeight: currentItem.implicitHeight
0017 
0018     property bool running: false
0019     property alias pluginType: altsModel.pluginType
0020     property alias inputData: altsModel.inputData
0021     property Component highlight
0022     property Component header
0023     property Component footer
0024     property variant verticalLayoutDirection: ListView.TopToBottom
0025     property Component delegate: Component {
0026         RowLayout {
0027             width: ListView.view.width
0028             Label {
0029                 Layout.fillWidth: true
0030                 text: display
0031                 elide: Text.ElideRight
0032             }
0033             Button {
0034                 text: i18nd("libpurpose6_quick", "Use")
0035                 onClicked: createJob(index);
0036             }
0037             Keys.onReturnPressed: createJob(index)
0038             Keys.onEnterPressed: createJob(index)
0039         }
0040     }
0041 
0042     /**
0043      * Signals when the job finishes, reports the
0044      * @p error code and a text @p message.
0045      *
0046      * @p output will specify the output offered by the job
0047      */
0048     signal finished(var output, int error, string message)
0049 
0050     PurposeAlternativesModel {
0051         id: altsModel
0052     }
0053 
0054     /**
0055      * Adopts the job at the @p index.
0056      */
0057     function createJob(index) {
0058         stack.push(jobComponent, {index: index})
0059     }
0060 
0061     /**
0062      * Clears and returns back to the initial view.
0063      */
0064     function reset() {
0065         for(; stack.depth>1; stack.pop())
0066         {}
0067     }
0068 
0069     initialItem: ListView {
0070         ScrollBar.vertical: ScrollBar {}
0071         focus: true
0072         model: altsModel
0073 
0074         implicitHeight: contentHeight
0075 
0076         verticalLayoutDirection: stack.verticalLayoutDirection
0077         delegate: stack.delegate
0078         highlight: stack.highlight
0079         footer: stack.footer
0080         header: stack.header
0081     }
0082 
0083     Component {
0084         id: jobComponent
0085 
0086         JobView {
0087             id: jobView
0088             model: altsModel
0089 
0090             onStateChanged: {
0091                 if (state === PurposeJobController.Finished || state === PurposeJobController.Error) {
0092                     stack.finished(jobView.job.output, jobView.job.error, jobView.job.errorString);
0093                 } else if (state === PurposeJobController.Cancelled) {
0094                     stack.pop();
0095                 }
0096             }
0097 
0098             Component.onCompleted: start()
0099         }
0100     }
0101 }