main.qml 4.27 KB
Newer Older
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * Copyright 2015 Aleix Pol Gonzalez <aleixpol@kde.org>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License or (at your option) version 3 or any later version
 * accepted by the membership of KDE e.V. (or its successor approved
 * by the membership of KDE e.V.), which shall act as a proxy
 * defined in Section 14 of version 3 of the license.
 *
 * 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
18
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
19 20 21
 */

import QtQuick 2.2
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
22
import QtQuick.Controls 2.1
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
23
import QtQuick.Layouts 1.1
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
24
import org.kde.kirigami 2.0 as Kirigami
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
25 26
import org.kde.kdeconnect 1.0

27
Kirigami.ApplicationWindow
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
28 29 30
{
    id: root
    visible: true
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
31
    width: 900
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
32 33
    height: 500

34 35
    Kirigami.Action {
        id: findDevicesAction
36
        text: i18nd("kdeconnect-app", "Find devices...")
37
        iconName: "list-add"
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
38
        checked: pageStack.currentItem && pageStack.currentItem.objectName == "FindDevices"
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
39

40 41
        onTriggered: {
            root.pageStack.clear()
Nicolas Fella's avatar
Nicolas Fella committed
42
            root.pageStack.push(Qt.resolvedUrl("FindDevicesPage.qml"));
43 44 45
        }
    }

46
    globalDrawer: Kirigami.GlobalDrawer {
47
        id: drawer
48

49 50 51
        modal: !root.wideScreen
        handleVisible: !root.wideScreen

52 53 54 55 56 57 58 59
        topContent: RowLayout {
            width: parent.width
            DBusProperty {
                id: announcedNameProperty
                object: DaemonDbusInterface
                read: "announcedName"
                defaultValue: ""
            }
60

61 62 63 64 65 66 67 68 69
            TextField {
                id: nameField
                visible: false
                Layout.fillWidth: true
                Layout.leftMargin: Kirigami.Units.smallSpacing
                text: announcedNameProperty.value
                onAccepted: {
                    DaemonDbusInterface.setAnnouncedName(text)
                    text = Qt.binding(function() {return announcedNameProperty.value})
70
                }
71
            }
72

73 74 75 76
            Label {
                text: announcedNameProperty.value
                visible: !nameField.visible
                Layout.fillWidth: true
77
                elide: Qt.ElideRight
78 79 80
                font.pointSize: 18
                Layout.leftMargin: Kirigami.Units.smallSpacing
            }
81

82 83 84 85 86
            Button {
                icon.name: nameField.visible ? "dialog-ok-apply" : "entry-edit"
                onClicked: {
                    nameField.visible = !nameField.visible
                    nameField.accepted()
87 88
                }
            }
Nicolas Fella's avatar
Nicolas Fella committed
89
        }
90

91 92
        property var objects: [findDevicesAction]
        Instantiator {
93
            model: DevicesSortProxyModel {
94
                sourceModel: DevicesModel { displayFilter: DevicesModel.Paired | DevicesModel.Reachable }
95
            }
96
            delegate: Kirigami.Action {
Nicolas Fella's avatar
Nicolas Fella committed
97 98
                icon.name: model.iconName
                icon.color: "transparent"
99
                text: display + "\n" + toolTip
100
                visible: status & DevicesModel.Reachable
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
101
                checked: pageStack.currentItem && pageStack.currentItem.currentDevice == device
102
                onTriggered: {
103 104
                    root.pageStack.clear()
                    root.pageStack.push(
Nicolas Fella's avatar
Nicolas Fella committed
105
                        Qt.resolvedUrl("DevicePage.qml"),
106 107
                        {currentDevice: device}
                    );
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
108 109
                }
            }
110 111 112 113 114 115 116 117 118 119 120 121

            onObjectAdded: {
                drawer.objects.push(object)
                drawer.objects = drawer.objects
            }
            onObjectRemoved: {
                var idx = drawer.objects.indexOf(object);
                if (idx>=0) {
                    var removed = drawer.objects.splice(idx, 1)
                    drawer.objects = drawer.objects
                }
            }
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
122
        }
123
        actions: objects
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
124
    }
125

126 127 128 129
    contextDrawer: Kirigami.ContextDrawer {
        id: contextDrawer
    }

Nicolas Fella's avatar
Nicolas Fella committed
130
    pageStack.initialPage: Qt.resolvedUrl("FindDevicesPage.qml")
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
131
}