FullRepresentation.qml 5.47 KB
Newer Older
Marco Martin's avatar
Marco Martin committed
1
2
3
4
5
/*
 *   Copyright 2011 Viranch Mehta <viranch.mehta@gmail.com>
 *   Copyright 2012 Jacopo De Simoi <wilderkde@gmail.com>
 *   Copyright 2014 David Edmundson <davidedmundson@kde.org>
 *   Copyright 2014 Marco Martin <mart@kde.org>
6
 *   Copyright 2020 Nate Graham <nate@kde.org>
Marco Martin's avatar
Marco Martin committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 *
 *
 *   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 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.
 */

25
import QtQuick 2.2
26
import QtQuick.Window 2.2
Marco Martin's avatar
Marco Martin committed
27
import QtQuick.Layouts 1.1
28

Marco Martin's avatar
Marco Martin committed
29
import org.kde.plasma.core 2.0 as PlasmaCore
30
31
import org.kde.plasma.components 2.0 as PlasmaComponents // For Highlight
import org.kde.plasma.components 3.0 as PlasmaComponents3
Marco Martin's avatar
Marco Martin committed
32
33
import org.kde.plasma.extras 2.0 as PlasmaExtras

34
PlasmaComponents3.Page {
35
36
37
    id: fullRep
    property bool spontaneousOpen: false

Nate Graham's avatar
Nate Graham committed
38
39
    Layout.minimumWidth: PlasmaCore.Units.gridUnit * 12
    Layout.minimumHeight: PlasmaCore.Units.gridUnit * 12
Marco Martin's avatar
Marco Martin committed
40

41
    header: PlasmaExtras.BasicPlasmoidHeading {
42
        visible: !(plasmoid.containmentDisplayHints & PlasmaCore.Types.ContainmentDrawsPlasmoidHeading) || devicenotifier.mountedRemovables > 1
43
44
45
        PlasmaComponents3.ToolButton {
            id: unmountAll
            visible: devicenotifier.mountedRemovables > 1;
46

47
48
            icon.name: "media-eject"
            text: i18n("Remove All")
49

50
51
            PlasmaComponents3.ToolTip {
                text: i18n("Click to safely remove all devices")
52
53
54
            }
        }
    }
55
    
56
57
58
59
60
    MouseArea {
        id: fullRepMouseArea
        hoverEnabled: true
    }

61
62
63
64
65
66
    PlasmaCore.DataSource {
        id: userActivitySource
        engine: "powermanagement"
        connectedSources: "UserActivity"
        property int polls: 0
        //poll only on plasmoid expanded
67
        interval: !fullRepMouseArea.containsMouse && !fullRep.Window.active && spontaneousOpen && plasmoid.expanded ? 3000 : 0
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
        onIntervalChanged: polls = 0;
        onDataChanged: {
            //only do when polling
            if (interval == 0 || polls++ < 1) {
                return;
            }

            if (userActivitySource.data["UserActivity"]["IdleTime"] < interval) {
                plasmoid.expanded = false;
                spontaneousOpen = false;
            }
        }
    }


83
84
85
86
87
88
89
90
91
92
    // this item is reparented to a delegate that is showing a message to draw focus to it
    PlasmaComponents.Highlight {
        id: messageHighlight
        visible: false

        OpacityAnimator {
            id: messageHighlightAnimator
            target: messageHighlight
            from: 1
            to: 0
93
            duration: PlasmaCore.Units.veryLongDuration * 8
94
            easing.type: Easing.InOutQuad
95
        }
96
97
98

        Connections {
            target: statusSource
Konrad Materka's avatar
Konrad Materka committed
99
            function onLastChanged() {
100
101
102
103
104
                if (!statusSource.last) {
                    messageHighlightAnimator.stop()
                    messageHighlight.visible = false
                }
            }
105
        }
106
107
108
109
110
111
112
113
114
115
116
117
118

        function highlight(item) {
            parent = item
            width = Qt.binding(function() { return item.width })
            height = Qt.binding(function() { return item.height })
            opacity = 1 // Animator is threaded so the old opacity might be visible for a frame or two
            visible = true
            messageHighlightAnimator.start()
        }
    }

    Connections {
        target: plasmoid
119
        function onExpandedChanged() {
120
            if (!plasmoid.expanded) {
121
                statusSource.clearMessage();
122
123
124
125
            }
        }
    }

126
    PlasmaExtras.ScrollArea {
Marco Martin's avatar
Marco Martin committed
127
        anchors.fill: parent
Marco Martin's avatar
Marco Martin committed
128

129
130
131
132
        ListView {
            id: notifierDialog
            focus: true
            boundsBehavior: Flickable.StopAtBounds
Marco Martin's avatar
Marco Martin committed
133

134
            model: filterModel
Marco Martin's avatar
Marco Martin committed
135

136
            delegate: DeviceItem {
137
                width: notifierDialog.width
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
                udi: DataEngineSource
            }
            highlight: PlasmaComponents.Highlight { }

            currentIndex: devicenotifier.currentIndex

            //this is needed to make SectionScroller actually work
            //acceptable since one doesn't have a billion of devices
            cacheBuffer: 1000

            section {
                property: "Type Description"
                delegate: Item {
                    height: childrenRect.height
                    width: notifierDialog.width
                    PlasmaExtras.Heading {
                        level: 3
                        opacity: 0.6
                        text: section
Marco Martin's avatar
Marco Martin committed
157
158
                    }
                }
159
            }
160

161
162
            PlasmaExtras.PlaceholderMessage {
                anchors.centerIn: parent
Nate Graham's avatar
Nate Graham committed
163
                width: parent.width - (PlasmaCore.Units.largeSpacing * 4)
164
                text: plasmoid.configuration.removableDevices ? i18n("No removable devices attached") : i18n("No disks available")
165
                visible: notifierDialog.count === 0 && !devicenotifier.pendingDelegateRemoval
Marco Martin's avatar
Marco Martin committed
166
167
168
            }
        }
    }
169
}