/*SPDX-FileCopyrightText: 2013 Heena Mahour <heena393@gmail.com>SPDX-FileCopyrightText: 2015, 2016 Kai Uwe Broulik <kde@privat.broulik.de>SPDX-FileCopyrightText: 2023 Nate Graham <nate@kde.org>SPDX-License-Identifier: GPL-2.0-or-later*/pragma ComponentBehavior: Boundimport QtQuickimport org.kde.plasma.plasmoidimport org.kde.plasma.core as PlasmaCoreimport org.kde.plasma.extras as PlasmaExtrasimport org.kde.draganddrop as DragDropimport plasma.applet.org.kde.plasma.trash as TrashPrivateimport org.kde.kirigami as Kirigamiimport org.kde.kcmutils as KCMimport org.kde.config as KConfigPlasmoidItem {id: rootreadonly property bool inPanel: (Plasmoid.location === PlasmaCore.Types.TopEdge|| Plasmoid.location === PlasmaCore.Types.RightEdge|| Plasmoid.location === PlasmaCore.Types.BottomEdge|| Plasmoid.location === PlasmaCore.Types.LeftEdge)readonly property bool hasContents: TrashPrivate.Trash.count > 0property bool containsAcceptableDrag: falsePlasmoid.title: i18nc("@title the name of the Trash widget", "Trash")toolTipSubText: {if (TrashPrivate.Trash.emptying) {return i18nc("@info:status The trash is being emptied", "Emptyingβ¦");} else if (TrashPrivate.Trash.listing && !delayListingTimer.running) {return i18nc("@info:status Counting the number of items in trash", "Countingβ¦");} else if (hasContents) {return i18ncp("@info:status The trash contains this many items in it", "One item", "%1 items", TrashPrivate.Trash.count);} else {return i18nc("@info:status The trash is empty", "Empty");}}Plasmoid.backgroundHints: PlasmaCore.Types.NoBackgroundPlasmoid.icon: {let iconName = (hasContents ? "user-trash-full" : "user-trash");if (inPanel) {return iconName += "-symbolic";}return iconName;}Plasmoid.status: hasContents ? PlasmaCore.Types.ActiveStatus : PlasmaCore.Types.PassiveStatusPlasmoid.busy: TrashPrivate.Trash.emptyingPlasmoid.onActivated: TrashPrivate.Trash.openTrash()Keys.onPressed: event => {switch (event.key) {case Qt.Key_Space:case Qt.Key_Enter:case Qt.Key_Return:case Qt.Key_Select:Plasmoid.activated();break;}}Accessible.name: Plasmoid.titleAccessible.description: toolTipSubTextAccessible.role: Accessible.ButtonPlasmoid.contextualActions: [PlasmaCore.Action {text: i18nc("@action:inmenu Open the trash", "Open")icon.name: "document-open-symbolic"onTriggered: Plasmoid.activated()},PlasmaCore.Action {text: i18nc("@action:inmenu Empty the trash", "Empty")icon.name: "trash-empty-symbolic"enabled: root.hasContents && !TrashPrivate.Trash.emptyingonTriggered: TrashPrivate.Trash.emptyTrash()},PlasmaCore.Action {text: i18nc("@action:inmenu", "Trash Settingsβ¦")icon.name: "configure-symbolic"visible: KConfig.KAuthorized.authorizeControlModule("kcm_trash")onTriggered: KCM.KCMLauncher.open("kcm_trash")}]Component.onCompleted: {Plasmoid.removeInternalAction("configure");}// Avoid briefly flashing "Counting"Timer {id: delayListingTimerinterval: 500running: TrashPrivate.Trash.listingrepeat: false}// Only exists because the default CompactRepresentation doesn't:// - allow defining a custom drop handler// - expose the ability to show text below or beside the icon// TODO remove once it gains those featurespreferredRepresentation: fullRepresentationfullRepresentation: MouseArea {id: mouseAreaactiveFocusOnTab: truehoverEnabled: trueonClicked: Plasmoid.activated()DragDrop.DropArea {anchors.fill: parentpreventStealing: trueonDragEnter: event => root.containsAcceptableDrag = TrashPrivate.Trash.trashableUrls(event.mimeData.urls).length > 0onDragLeave: root.containsAcceptableDrag = falseonDrop: event => {root.containsAcceptableDrag = falsevar trashableUrls = TrashPrivate.Trash.trashableUrls(event.mimeData.urls)if (trashableUrls.length > 0) {TrashPrivate.Trash.trashUrls(trashableUrls)event.accept(Qt.MoveAction)} else {event.accept(Qt.IgnoreAction) // prevent Plasma from spawning an applet}}}Kirigami.Icon {source: Plasmoid.iconanchors {left: parent.leftright: parent.righttop: parent.topbottom: root.inPanel ? parent.bottom: text.top}active: mouseArea.containsMouse || root.containsAcceptableDrag}PlasmaExtras.ShadowedLabel {id: textanchors {horizontalCenter: parent.horizontalCenterbottom: parent.bottom}width: Math.round(text.implicitWidth + Kirigami.Units.smallSpacing) // make sure label is not blurrytext: Plasmoid.title + "\n" + root.toolTipSubTexthorizontalAlignment: Text.AlignHCentervisible: !root.inPanel}PlasmaCore.ToolTipArea {anchors.fill: parentmainText: Plasmoid.titlesubText: root.toolTipSubText}}}