Warning, /plasma/plasma-desktop/applets/trash/package/contents/ui/main.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2013 Heena Mahour <heena393@gmail.com>
0003     SPDX-FileCopyrightText: 2015, 2016 Kai Uwe Broulik <kde@privat.broulik.de>
0004     SPDX-FileCopyrightText: 2023 Nate Graham <nate@kde.org>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 import QtQuick 2.15
0009 import QtQuick.Layouts 1.1
0010 
0011 import org.kde.plasma.plasmoid 2.0
0012 import org.kde.plasma.core as PlasmaCore
0013 import org.kde.plasma.extras as PlasmaExtras
0014 import org.kde.draganddrop 2.0 as DragDrop
0015 import org.kde.plasma.private.trash 1.0 as TrashPrivate
0016 import org.kde.kirigami 2.20 as Kirigami
0017 
0018 import org.kde.kcmutils as KCM
0019 import org.kde.config as KConfig
0020 
0021 PlasmoidItem {
0022     id: root
0023 
0024     readonly property bool inPanel: (Plasmoid.location === PlasmaCore.Types.TopEdge
0025         || Plasmoid.location === PlasmaCore.Types.RightEdge
0026         || Plasmoid.location === PlasmaCore.Types.BottomEdge
0027         || Plasmoid.location === PlasmaCore.Types.LeftEdge)
0028     readonly property bool hasContents: dirModel.count > 0
0029 
0030     property bool containsAcceptableDrag: false
0031 
0032     Plasmoid.title: i18nc("@title the name of the Trash widget", "Trash")
0033     toolTipSubText: hasContents
0034         ? i18ncp("@info:status The trash contains this many items in it", "One item", "%1 items", dirModel.count)
0035         : i18nc("@info:status The trash is empty", "Empty")
0036 
0037     Plasmoid.backgroundHints: PlasmaCore.Types.NoBackground
0038     Plasmoid.icon: {
0039         let iconName = (hasContents ? "user-trash-full" : "user-trash");
0040 
0041         if (inPanel) {
0042             return iconName += "-symbolic";
0043         }
0044 
0045         return iconName;
0046     }
0047 
0048     Plasmoid.onActivated: Qt.openUrlExternally("trash:/")
0049 
0050     Keys.onPressed: {
0051         switch (event.key) {
0052         case Qt.Key_Space:
0053         case Qt.Key_Enter:
0054         case Qt.Key_Return:
0055         case Qt.Key_Select:
0056             Plasmoid.activated();
0057             break;
0058         }
0059     }
0060     Accessible.name: Plasmoid.title
0061     Accessible.description: toolTipSubText
0062     Accessible.role: Accessible.Button
0063 
0064     TrashPrivate.DirModel {
0065         id: dirModel
0066         url: "trash:/"
0067     }
0068 
0069     Plasmoid.contextualActions: [
0070         PlasmaCore.Action {
0071             text: i18nc("@action:inmenu Open the trash", "Open")
0072             icon.name: "document-open-symbolic"
0073             onTriggered: Plasmoid.activated()
0074         },
0075         PlasmaCore.Action {
0076             text: i18nc("@action:inmenu Empty the trash", "Empty")
0077             icon.name: "trash-empty-symbolic"
0078             enabled: hasContents
0079             onTriggered: TrashPrivate.Trash.emptyTrash()
0080         },
0081         PlasmaCore.Action {
0082             text: i18nc("@action:inmenu", "Trash Settingsā€¦")
0083             icon.name: "configure-symbolic"
0084             visible: KConfig.KAuthorized.authorizeControlModule("kcm_trash")
0085             onTriggered: KCM.KCMLauncher.open("kcm_trash")
0086         }
0087     ]
0088 
0089     Component.onCompleted: {
0090         Plasmoid.removeInternalAction("configure");
0091     }
0092 
0093     // Only exists because the default CompactRepresentation doesn't:
0094     // - allow defining a custom drop handler
0095     // - expose the ability to show text below or beside the icon
0096     // TODO remove once it gains those features
0097     preferredRepresentation: fullRepresentation
0098     fullRepresentation: MouseArea {
0099         id: mouseArea
0100 
0101         activeFocusOnTab: true
0102         hoverEnabled: true
0103 
0104         onClicked: Plasmoid.activated()
0105 
0106         DragDrop.DropArea {
0107             anchors.fill: parent
0108             preventStealing: true
0109             onDragEnter: root.containsAcceptableDrag = TrashPrivate.Trash.trashableUrls(event.mimeData.urls).length > 0
0110             onDragLeave: root.containsAcceptableDrag = false
0111 
0112             onDrop: {
0113                 root.containsAcceptableDrag = false
0114 
0115                 var trashableUrls = TrashPrivate.Trash.trashableUrls(event.mimeData.urls)
0116                 if (trashableUrls.length > 0) {
0117                     TrashPrivate.Trash.trashUrls(trashableUrls)
0118                     event.accept(Qt.MoveAction)
0119                 } else {
0120                     event.accept(Qt.IgnoreAction) // prevent Plasma from spawning an applet
0121                 }
0122             }
0123         }
0124 
0125         Kirigami.Icon {
0126             source: Plasmoid.icon
0127             anchors {
0128                 left: parent.left
0129                 right: parent.right
0130                 top: parent.top
0131                 bottom: root.inPanel ? parent.bottom: text.top
0132             }
0133             active: mouseArea.containsMouse || root.containsAcceptableDrag
0134         }
0135 
0136         PlasmaExtras.ShadowedLabel {
0137             id: text
0138             anchors {
0139                 horizontalCenter: parent.horizontalCenter
0140                 bottom: parent.bottom
0141             }
0142             width: Math.round(text.implicitWidth + Kirigami.Units.smallSpacing) // make sure label is not blurry
0143             text: Plasmoid.title + "\n" + root.toolTipSubText
0144             horizontalAlignment: Text.AlignHCenter
0145             visible: !root.inPanel
0146         }
0147 
0148         PlasmaCore.ToolTipArea {
0149             anchors.fill: parent
0150             mainText: Plasmoid.title
0151             subText:  root.toolTipSubText
0152         }
0153     }
0154 }