DeviceDelegate.qml 9.64 KB
Newer Older
1
2
/**
 * Copyright 2013 Albert Vaca <albertvaka@gmail.com>
3
 *
4
5
6
7
8
9
10
 * 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.
11
 *
12
13
14
15
 * 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.
16
 *
17
 * 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/>.
19
20
 */

21
import QtQuick 2.1
22
import QtQuick.Layouts 1.1
23
24
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
25
import org.kde.plasma.components 3.0 as PlasmaComponents3
26
import org.kde.kdeconnect 1.0
27
import QtQuick.Dialogs 1.0
28
import QtQuick.Controls 2.4
29

30
31
32
PlasmaComponents.ListItem
{
    id: root
33
    readonly property QtObject device: DeviceDbusInterfaceFactory.create(model.deviceId)
34

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
    DropArea {
        id: fileDropArea
        anchors.fill: parent

        onDropped: {
            if (drop.hasUrls) {

                var urls = [];

                for (var v in drop.urls) {
                    if (drop.urls[v] != null) {
                        if (urls.indexOf(drop.urls[v].toString()) == -1) {
                            urls.push(drop.urls[v].toString());
                        }
                    }
                }

                var i;
                for (i = 0; i < urls.length; i++) {
                    share.plugin.shareUrl(urls[i]);
                }
            }
            drop.accepted = true;
        }

        PlasmaCore.ToolTipArea {
            id: dropAreaToolTip
            anchors.fill: parent
            location: plasmoid.location
            active: true
            mainText: i18n("File Transfer")
            subText: i18n("Drop a file to transfer it onto your phone.")
        }
    }

70
71
    Column {
        width: parent.width
72

David Edmundson's avatar
David Edmundson committed
73
        RowLayout
Samoilenko Yuri's avatar
Samoilenko Yuri committed
74
        {
75
            width: parent.width
Nicolas Fella's avatar
Nicolas Fella committed
76
77
78
79
            Battery {
                id: battery
                device: root.device
            }
80

Samoilenko Yuri's avatar
Samoilenko Yuri committed
81
            PlasmaComponents.Label {
82
                id: deviceName
David Edmundson's avatar
David Edmundson committed
83
                elide: Text.ElideRight
84
                text: (battery.available && battery.charge > -1) ? i18n("%1 (%2)", display, battery.displayString) : display
David Edmundson's avatar
David Edmundson committed
85
                Layout.fillWidth: true
86
                textFormat: Text.PlainText
David Edmundson's avatar
David Edmundson committed
87
88
            }

89
90
            PlasmaComponents3.ToolButton {
                id: overflowMenu
91
92
                icon.name: "application-menu"

93
                onClicked: {
94
                    menu.open(overflowMenu, overflowMenu.height)
95
96
                }

97
                PlasmaComponents.ContextMenu {
98
99
100
                    id: menu

                    //Share
101
                    PlasmaComponents.MenuItem
102
103
104
105
106
107
                    {
                        FileDialog {
                            id: fileDialog
                            title: i18n("Please choose a file")
                            folder: shortcuts.home
                            selectMultiple: true
108
                            onAccepted: fileDialog.fileUrls.forEach(url => share.plugin.shareUrl(url))
109
                        }
David Edmundson's avatar
David Edmundson committed
110

111
                        id: shareFile
112
                        icon: "document-share"
113
114
                        visible: share.available
                        text: i18n("Share file")
115
                        onClicked: fileDialog.open()
116
                    }
David Edmundson's avatar
David Edmundson committed
117

118
                    //Find my phone
119
                    PlasmaComponents.MenuItem
120
121
122
123
124
                    {
                        FindMyPhone {
                            id: findmyphone
                            device: root.device
                        }
125

126
                        id: ring
127
                        icon: "irc-voice"
128
129
130
131
132
133
134
                        visible: findmyphone.available
                        text: i18n("Ring my phone")

                        onClicked: {
                            findmyphone.ring()
                        }
                    }
135

136
                    //SFTP
137
                    PlasmaComponents.MenuItem
138
139
140
141
142
                    {
                        Sftp {
                            id: sftp
                            device: root.device
                        }
143

144
                        id: browse
145
                        icon: "document-open-folder"
146
147
                        visible: sftp.available
                        text: i18n("Browse this device")
148

149
150
151
152
                        onClicked: {
                            sftp.browse()
                        }
                    }
153

154
                    //SMS
155
                    PlasmaComponents.MenuItem
156
157
158
159
160
                    {
                        SMS {
                            id: sms
                            device: root.device
                        }
161

162
                        icon: "message-new"
163
164
165
166
167
168
169
                        visible: sms.available
                        text: i18n("SMS Messages")

                        onClicked: {
                            sms.plugin.launchApp()
                        }
                    }
170
171
                }
            }
172
        }
173

Holger Kaelberer's avatar
Holger Kaelberer committed
174
175
        //RemoteKeyboard
        PlasmaComponents.ListItem {
176
            visible: remoteKeyboard.remoteState
Holger Kaelberer's avatar
Holger Kaelberer committed
177
178
            width: parent.width

179
            RowLayout {
Holger Kaelberer's avatar
Holger Kaelberer committed
180
181
182
183
184
185
186
187
                width: parent.width
                spacing: 5

                PlasmaComponents.Label {
                    id: remoteKeyboardLabel
                    text: i18n("Remote Keyboard")
                }

188
189
190
191
                RemoteKeyboard {
                    id: remoteKeyboard
                    device: root.device
                    Layout.fillWidth: true
Holger Kaelberer's avatar
Holger Kaelberer committed
192
193
194
195
                }
            }
        }

196
197
198
        //Notifications
        PlasmaComponents.ListItem {
            visible: notificationsModel.count>0
Albert Vaca Cintora's avatar
Albert Vaca Cintora committed
199
            enabled: true
200
            PlasmaComponents.Label {
Nicolas Fella's avatar
Nicolas Fella committed
201
                text: i18n("Notifications:")
202
            }
203
            PlasmaComponents.ToolButton {
Albert Vaca Cintora's avatar
Albert Vaca Cintora committed
204
205
                enabled: true
                visible: notificationsModel.isAnyDimissable;
206
                anchors.right: parent.right
207
                iconSource: "edit-clear-history"
208
                tooltip: i18n("Dismiss all notifications")
Albert Vaca Cintora's avatar
Albert Vaca Cintora committed
209
                onClicked: notificationsModel.dismissAll();
210
211
212
213
214
215
            }
        }
        Repeater {
            id: notificationsView
            model: NotificationsModel {
                id: notificationsModel
216
                deviceId: root.device.id()
217
218
            }
            delegate: PlasmaComponents.ListItem {
219
220
221
222
                id: listitem
                enabled: true
                onClicked: checked = !checked

223
224
225
226
227
228
229
                PlasmaCore.IconItem {
                    id: notificationIcon
                    source: appIcon
                    width: (valid && appIcon.length) ? dismissButton.width : 0
                    height: width
                    anchors.left: parent.left
                }
230
                PlasmaComponents.Label {
231
                    text: appName + ": " + (title.length>0 ? (appName==title?notitext:title+": "+notitext) : display)
232
233
                    anchors.right: replyButton.left
                    anchors.left: notificationIcon.right
234
235
                    elide: listitem.checked ? Text.ElideNone : Text.ElideRight
                    maximumLineCount: listitem.checked ? 0 : 1
Albert Vaca Cintora's avatar
Albert Vaca Cintora committed
236
                    wrapMode: Text.WordWrap
237
                }
238
239
240
241
242
243
                PlasmaComponents.ToolButton {
                    id: replyButton
                    visible: repliable
                    enabled: repliable
                    anchors.right: dismissButton.left
                    iconSource: "mail-reply-sender"
244
                    tooltip: i18n("Reply")
245
246
                    onClicked: dbusInterface.reply();
                }
247
                PlasmaComponents.ToolButton {
Albert Vaca Cintora's avatar
Albert Vaca Cintora committed
248
                    id: dismissButton
Albert Vaca Cintora's avatar
Albert Vaca Cintora committed
249
250
                    visible: notificationsModel.isAnyDimissable;
                    enabled: dismissable
251
252
                    anchors.right: parent.right
                    iconSource: "window-close"
253
                    tooltip: i18n("Dismiss")
254
255
256
257
258
                    onClicked: dbusInterface.dismiss();
                }
            }
        }

259
260
261
262
263
264
        RemoteCommands {
            id: rc
            device: root.device
        }

        // Commands
Nicolas Fella's avatar
Nicolas Fella committed
265
        RowLayout {
266
            visible: rc.available
Nicolas Fella's avatar
Nicolas Fella committed
267
268
            width: parent.width

269
            PlasmaComponents.Label {
270
                text: i18n("Run command")
Nicolas Fella's avatar
Nicolas Fella committed
271
                Layout.fillWidth: true
272
            }
Nicolas Fella's avatar
Nicolas Fella committed
273

274
275
276
277
278
279
            PlasmaComponents.Button
            {
                id: addCommandButton
                iconSource: "list-add"
                tooltip: i18n("Add command")
                onClicked: rc.plugin.editCommands()
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
280
                visible: rc.plugin && rc.plugin.canAddCommand
281
            }
282
283
284
285
286
287
288
289
290
291
292
        }
        Repeater {
            id: commandsView
            visible: rc.available
            model: RemoteCommandsModel {
                id: commandsModel
                deviceId: rc.device.id()
            }
            delegate: PlasmaComponents.ListItem {
                enabled: true
                onClicked: rc.plugin.triggerCommand(key)
293

294
295
296
297
298
                PlasmaComponents.Label {
                    text: name + "\n" + command
                }
            }
        }
299
300
301
302
303
304

        // Share
        Share {
            id: share
            device: root.device
        }
305
    }
306
}