..
Viewing
Root.qml
157 lines (139 loc) • 4.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157 | import QtQuick 2.0
import QtQuick.Layouts 1.1
import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.extras 2.0 as PlasmaExtras
Item {
property Component fullRepresentation: Component {
FullRepresentation {
}
}
id: devicenotifier
property string devicesType: "removable"
property string expandedDevice
property string popupIcon: "device-notifier"
property bool itemClicked: false
property int currentExpanded: -1
property int currentIndex: -1
PlasmaCore.DataSource {
id: hpSource
engine: "hotplug"
connectedSources: sources
interval: 0
onSourceAdded: {
disconnectSource(source);
connectSource(source);
}
onSourceRemoved: {
disconnectSource(source);
}
}
PlasmaCore.DataSource {
id: sdSource
engine: "soliddevice"
connectedSources: hpSource.sources
interval: plasmoid.expanded ? 5000 : 0
property string last
onSourceAdded: {
disconnectSource(source);
connectSource(source);
last = source;
processLastDevice(true);
}
onSourceRemoved: {
if (expandedDevice == source) {
devicenotifier.currentExpanded = -1;
expandedDevice = "";
}
disconnectSource(source);
}
onDataChanged: {
processLastDevice(true);
}
onNewData: {
last = sourceName;
processLastDevice(false);
}
function processLastDevice(expand) {
if (last != "") {
if (devicesType == "all" ||
(devicesType == "removable" && data[last] && data[last]["Removable"] == true) ||
(devicesType == "nonRemovable" && data[last] && data[last]["Removable"] == false)) {
if (expand && hpSource.data[last]["added"]) {
expandDevice(last)
}
last = "";
}
}
}
}
PlasmaCore.SortFilterModel {
id: filterModel
sourceModel: PlasmaCore.DataModel {
dataSource: sdSource
}
filterRole: "Removable"
filterRegExp: {
var all = false // devicenotifier.Plasmoid.configuration.allDevices;
var removable = true //devicenotifier.Plasmoid.configuration.removableDevices;
if (all == true) {
devicesType = "all";
return "";
} else if (removable == true) {
devicesType = "removable";
return "true";
} else {
devicesType = "nonRemovable";
return "false";
}
}
sortRole: "Timestamp"
sortOrder: Qt.DescendingOrder
}
function popupEventSlot(popped) {
if (!popped) {
// reset the property that lets us remember if an item was clicked
// (versus only hovered) for autohide purposes
devicenotifier.itemClicked = true;
expandedDevice = "";
devicenotifier.currentExpanded = -1;
devicenotifier.currentIndex = -1;
}
}
function expandDevice(udi)
{
if (hpSource.data[udi]["actions"].length > 1) {
expandedDevice = udi
}
// reset the property that lets us remember if an item was clicked
// (versus only hovered) for autohide purposes
devicenotifier.itemClicked = false;
devicenotifier.popupIcon = "preferences-desktop-notification";
//plasmoid.expanded = true;
// expandTimer.restart();
popupIconTimer.restart()
}
function isMounted (udi) {
var types = sdSource.data[udi]["Device Types"];
if (types.indexOf("Storage Access")>=0) {
if (sdSource.data[udi]["Accessible"]) {
return true;
}
else {
return false;
}
}
else if (types.indexOf("Storage Volume")>=0 && types.indexOf("OpticalDisc")>=0) {
return true;
}
else {
return false;
}
}
Timer {
id: popupIconTimer
interval: 2500
onTriggered: devicenotifier.popupIcon = "device-notifier";
}
}
|
|