Warning, /plasma/plasma-workspace/applets/systemtray/package/contents/ui/SystemTrayState.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2020 Konrad Materka <materka@gmail.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 import QtQuick 2.12
0008 import org.kde.plasma.core as PlasmaCore
0009 import org.kde.plasma.plasmoid 2.0
0010 
0011 //This object contains state of the SystemTray, mainly related to the 'expanded' state
0012 QtObject {
0013     //true if System Tray is 'expanded'. It may be when:
0014     // - there is an active applet or
0015     // - 'Status and Notification' with hidden items is shown
0016     property bool expanded: false
0017     //set when there is an applet selected
0018     property Item activeApplet
0019 
0020     //allow expanded change only when activated at least once
0021     //this is to suppress expanded state change during Plasma startup
0022     property bool acceptExpandedChange: false
0023 
0024     // These properties allow us to keep track of where the expanded applet
0025     // was and is on the panel, allowing PlasmoidPopupContainer.qml to animate
0026     // depending on their locations.
0027     property int oldVisualIndex: -1
0028     property int newVisualIndex: -1
0029 
0030     function setActiveApplet(applet, visualIndex) {
0031         if (visualIndex === undefined) {
0032             oldVisualIndex = -1
0033             newVisualIndex = -1
0034         } else {
0035             oldVisualIndex = (activeApplet && activeApplet.status === PlasmaCore.Types.PassiveStatus) ? 9999 : newVisualIndex
0036             newVisualIndex = visualIndex
0037         }
0038 
0039         const oldApplet = activeApplet
0040         if (applet && !applet.preferredRepresentation) {
0041             applet.expanded = true;
0042         }
0043         if (!applet || !applet.preferredRepresentation) {
0044             activeApplet = applet;
0045         }
0046 
0047         if (oldApplet && oldApplet !== applet) {
0048             oldApplet.expanded = false
0049         }
0050 
0051         if (applet && !applet.preferredRepresentation) {
0052             expanded = true
0053         }
0054     }
0055 
0056     onExpandedChanged: {
0057         if (expanded) {
0058             Plasmoid.status = PlasmaCore.Types.RequiresAttentionStatus
0059         } else {
0060             Plasmoid.status = PlasmaCore.Types.PassiveStatus;
0061             if (activeApplet) {
0062                 // if not expanded we don't have an active applet anymore
0063                 activeApplet.expanded = false
0064                 activeApplet = null
0065             }
0066         }
0067         acceptExpandedChange = false
0068         root.expanded = expanded
0069     }
0070 
0071     //listen on SystemTray AppletInterface signals
0072     property Connections plasmoidConnections: Connections {
0073         target: Plasmoid
0074         //emitted when activation is requested, for example by using a global keyboard shortcut
0075         function onActivated() {
0076             acceptExpandedChange = true
0077         }
0078     }
0079 
0080     property Connections rootConnections: Connections {
0081         function onExpandedChanged() {
0082             if (acceptExpandedChange) {
0083                 expanded = root.expanded
0084             } else {
0085                 root.expanded = expanded
0086             }
0087         }
0088     }
0089 
0090     property Connections activeAppletConnections: Connections {
0091         target: activeApplet && activeApplet
0092 
0093         function onExpandedChanged() {
0094             if (activeApplet && !activeApplet.expanded) {
0095                 expanded = false
0096             }
0097         }
0098     }
0099 
0100 }