Commit 81db7443 authored by Thomas Surrel's avatar Thomas Surrel

[Device Notifier] Add a button to unmount all devices

Summary:
When at least two removable devices are mounted, a button shows
up that will allow to unmount all mounted removable devices.
This is convenient for removable drives with several partitions,
each of which have to be unmounted to be able to safely plug the
device out.

{F6330009}

FEATURE: 395644

Test Plan:
Plug and mount two devices.
Click on the new 'unmount all' button.

Reviewers: #plasma, #vdg, ngraham, broulik

Reviewed By: #plasma, #vdg, ngraham, broulik

Subscribers: abetts, broulik, ngraham, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D16212
parent ff34471a
......@@ -88,6 +88,15 @@ MouseArea {
}
}
Connections {
target: unmountAll
onClicked: {
if (model["Removable"] && mounted) {
actionTriggered();
}
}
}
// this keeps the delegate around for 5 seconds after the device has been
// removed in case there was a message, such as "you can now safely remove this"
ListView.onRemove: {
......
......@@ -110,12 +110,22 @@ MouseArea {
}
}
ColumnLayout {
Item {
anchors.fill: parent
PlasmaComponents.ToolButton {
id: unmountAll
visible: devicenotifier.mountedRemovables > 1;
anchors.right: parent.right
iconSource: "media-eject"
tooltip: i18n("Click to safely remove all devices")
text: i18n("Remove all")
implicitWidth: minimumWidth
}
PlasmaExtras.ScrollArea {
Layout.fillWidth: true
Layout.fillHeight: true
anchors.fill: parent
anchors.top: unmountAll.top
ListView {
id: notifierDialog
......
......@@ -48,6 +48,8 @@ Item {
property bool itemClicked: false
property int currentIndex: -1
property var connectedRemovables: []
property int mountedRemovables: 0
// QTBUG-50380: As soon as the item gets removed from the model, all of ListView's
// properties (count, contentHeight) pretend the delegate doesn't exist anymore
......@@ -116,6 +118,10 @@ Item {
connectSource(source);
last = source;
processLastDevice(true);
if (data[source].Removable) {
devicenotifier.connectedRemovables.push(source);
devicenotifier.connectedRemovables = devicenotifier.connectedRemovables;
}
}
onSourceRemoved: {
......@@ -123,10 +129,24 @@ Item {
expandedDevice = "";
}
disconnectSource(source);
var index = devicenotifier.connectedRemovables.indexOf(source);
if (index >= 0) {
devicenotifier.connectedRemovables.splice(index, 1);
devicenotifier.connectedRemovables = devicenotifier.connectedRemovables;
}
}
onDataChanged: {
processLastDevice(true);
var counter = 0;
for (var i = 0; i < devicenotifier.connectedRemovables.length; i++) {
if (isMounted(devicenotifier.connectedRemovables[i])) {
counter++;
}
}
if (counter != devicenotifier.mountedRemovables) {
devicenotifier.mountedRemovables = counter;
}
}
onNewData: {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment