RowItemDelegate.qml 7.22 KB
Newer Older
Jan Grulich's avatar
Jan Grulich committed
1
/*
2
 *   Copyright 2017 Martin Kacej <m.kacej@atlas.sk>
Jan Grulich's avatar
Jan Grulich committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Library General Public License as
 *   published by the Free Software Foundation; either version 2 or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU Library General Public License for more details
 *
 *   You should have received a copy of the GNU Library General Public
 *   License along with this program; if not, write to the
 *   Free Software Foundation, Inc.,
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

Martin Kacej's avatar
Martin Kacej committed
20 21
import QtQuick 2.6
import QtQuick.Controls 2.2 as Controls
22 23 24
import QtQuick.Layouts 1.2
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
Martin Kacej's avatar
Martin Kacej committed
25
import org.kde.plasma.networkmanagement 0.2 as PlasmaNM
Martin Kacej's avatar
Martin Kacej committed
26
import org.kde.kirigami 2.2 as Kirigami
27

28
Kirigami.SwipeListItem {
Martin Kacej's avatar
Martin Kacej committed
29
    id: listitem
30 31

    height: units.gridUnit * 3
32
    enabled: true
33
    backgroundColor: theme.backgroundColor
34

35
    property var map : []
36 37 38 39 40 41 42 43
    property bool predictableWirelessPassword: !Uuid && Type == PlasmaNM.Enums.Wireless &&
                                                   (SecurityType == PlasmaNM.Enums.StaticWep ||
                                                    SecurityType == PlasmaNM.Enums.WpaPsk ||
                                                    SecurityType == PlasmaNM.Enums.Wpa2Psk)

    onClicked: {
        changeState()
    }
Jan Grulich's avatar
Jan Grulich committed
44

45
    Item {
46

Martin Kacej's avatar
Martin Kacej committed
47
        height: parent.height
48
        width: parent.width
Martin Kacej's avatar
Martin Kacej committed
49
        anchors.fill: parent
50 51 52

        PlasmaCore.SvgItem {
            id: connectionSvgIcon
53

54 55
            anchors {
                left: parent.left
Martin Kacej's avatar
Martin Kacej committed
56 57
                leftMargin: units.gridUnit
                verticalCenter: parent.verticalCenter
58
            }
59 60
            height: units.iconSizes.big;
            width: height
61
            elementId: ConnectionIcon
62

63 64 65 66 67 68 69
            svg: PlasmaCore.Svg {
                multipleImages: true
                imagePath: "icons/network"
                colorGroup: PlasmaCore.ColorScope.colorGroup
            }
        }

70 71 72 73 74 75 76 77 78 79 80 81 82
        PlasmaComponents.BusyIndicator {
            id: connectingIndicator

            anchors {
                left: parent.left
                horizontalCenter: connectionSvgIcon.horizontalCenter
                verticalCenter: connectionSvgIcon.verticalCenter
            }
            height: units.iconSizes.medium; width: height
            running: ConnectionState == PlasmaNM.Enums.Activating
            visible: running
        }

Martin Kacej's avatar
Martin Kacej committed
83 84 85 86
        PlasmaComponents.Label {
            id: connectionNameLabel

            anchors {
87 88 89
                left: connectionSvgIcon.right
                leftMargin: units.gridUnit
                verticalCenter: connectionSvgIcon.verticalCenter
Martin Kacej's avatar
Martin Kacej committed
90 91 92 93 94 95 96
            }
            height: paintedHeight
            elide: Text.ElideRight
            font.weight: ConnectionState == PlasmaNM.Enums.Activated ? Font.DemiBold : Font.Normal
            font.italic: ConnectionState == PlasmaNM.Enums.Activating ? true : false
            text: ItemUniqueName
            textFormat: Text.PlainText
97
        }
98 99 100 101 102

        Item{
            id: connectionPasswordField

            anchors.left: connectionNameLabel.left
Martin Kacej's avatar
Martin Kacej committed
103
            anchors.verticalCenter: parent.verticalCenter
104 105 106 107 108 109 110 111 112
            height: units.gridUnit * 1.5
            visible: false

            onVisibleChanged: {
                connectionPasswordFieldField.text = ""
            }

            PasswordField{
                id: connectionPasswordFieldField
Martin Kacej's avatar
Martin Kacej committed
113
                securityType: SecurityType
114
                height: parent.height
115 116 117
                onAcceptableInputChanged: {
                    connectionPasswordFieldButton.enabled = acceptableInput
                }
118 119
            }

120
            Controls.Button{
121 122 123 124 125 126 127 128 129 130 131 132
                id: connectionPasswordFieldButton

                anchors.left: connectionPasswordFieldField.right
                width: units.gridUnit * 5
                height: parent.height
                text: "ok" // TODO icon, size

                onClicked: {
                    handler.addAndActivateConnection(DevicePath, SpecificPath, connectionPasswordFieldField.text);
                }
            }
        }
133
    }
Martin Kacej's avatar
Martin Kacej committed
134

135
    actions: [
136 137 138 139 140 141 142 143 144 145
        Kirigami.Action {
            iconName: "go-previous" // TODO better icon
            visible: ConnectionState != PlasmaNM.Enums.Activated
            onTriggered: changeState()
        },
        Kirigami.Action {
            iconName: "go-next" // TODO better icon
            visible: ConnectionState == PlasmaNM.Enums.Activated
            onTriggered: handler.deactivateConnection(ConnectionPath, DevicePath)
        },
146
        Kirigami.Action {
147 148
            iconName: "configure"
            onTriggered: getDetails()
149 150 151
        },
        Kirigami.Action {
            iconName: "remove"
152
            visible: (Uuid != "")? true : false
153
            onTriggered: forgetNetwork()
Martin Kacej's avatar
Martin Kacej committed
154
        }
155
    ]
156

157
    function getDetails() {
Martin Kacej's avatar
Martin Kacej committed
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
        applicationWindow().pageStack.push(networkDetailsViewComponent)
        if (networkDetailsViewComponent.status == Component.Ready){
            console.info("Network view ready")
            if (ConnectionDetails)
                networkDetailsViewComponentView.details = ConnectionDetails
            if (ConnectionDetails[1] !== "") {
                detailsDialog.titleText = ItemUniqueName
            } else {
                detailsDialog.titleText = i18n("Network details")
            }
            map = handler.getConnectionSettings(ConnectionPath,"ipv4")
            if (ConnectionState == PlasmaNM.Enums.Activated){
                networkDetailsViewComponentView.activeMap = handler.getActiveConnectionInfo(SpecificPath)
            }
            //networkDetailsViewContent.map = map
            networkDetailsViewComponentView.fillDetails()
            //applicationWindow().pageStack.push(networkDetailsViewComponent)

176
        }
177 178
    }

179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
    function changeState() {
        if (Uuid || !predictableWirelessPassword || connectionPasswordField.visible) {
            if (ConnectionState == PlasmaNM.Enums.Deactivated) {
                if (!predictableWirelessPassword && !Uuid) {
                    handler.addAndActivateConnection(DevicePath, SpecificPath);
                } else if (connectionPasswordField.visible) {
                            if (connectionPasswordFieldField.text != "") {
                                handler.addAndActivateConnection(DevicePath, SpecificPath, connectionPasswordFieldField.text);
                                connectionPasswordField.visible = false;
                            } else {
                                connectionPasswordField.visible = false;
                            }
                        } else {
                            handler.activateConnection(ConnectionPath, DevicePath, SpecificPath);
                        }
            }
        } else if (predictableWirelessPassword) {
           connectionPasswordField.visible = true;
        }
198
    }
199

Jan Grulich's avatar
Jan Grulich committed
200
    function forgetNetwork() {
201 202
        // TODO confirmation dialog
        handler.removeConnection(ConnectionPath)
203
    }
204
}