summaryrefslogtreecommitdiff
path: root/raveos-hyprland-theme/theme-data/dms/Modules/ControlCenter/Components/DetailHost.qml
blob: a3b115647238a829d32fcc72ac521eba2e376105 (plain)
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
import QtQuick
import qs.Common
import qs.Services
import qs.Modules.ControlCenter.Details

Item {
    id: root

    property string expandedSection: ""
    property var expandedWidgetData: null
    property var bluetoothCodecSelector: null
    property string screenName: ""
    property string screenModel: ""

    property var pluginDetailInstance: null
    property var widgetModel: null
    property var collapseCallback: null
    property real maxAvailableHeight: 9999

    function getDetailHeight(section) {
        switch (true) {
        case section === "wifi":
        case section === "bluetooth":
        case section === "builtin_vpn":
            return Math.min(350, maxAvailableHeight);
        case section.startsWith("brightnessSlider_"):
            return Math.min(400, maxAvailableHeight);
        case section.startsWith("plugin_"):
            if (pluginDetailInstance?.ccDetailHeight)
                return Math.min(pluginDetailInstance.ccDetailHeight, maxAvailableHeight);
            return Math.min(250, maxAvailableHeight);
        default:
            return Math.min(250, maxAvailableHeight);
        }
    }

    Loader {
        id: pluginDetailLoader
        width: parent.width
        height: parent.height - Theme.spacingS
        y: Theme.spacingS
        active: false
        sourceComponent: null
    }

    Loader {
        id: coreDetailLoader
        width: parent.width
        height: parent.height - Theme.spacingS
        y: Theme.spacingS
        active: false
        sourceComponent: null
    }

    Connections {
        target: coreDetailLoader.item
        enabled: root.expandedSection.startsWith("brightnessSlider_")
        ignoreUnknownSignals: true

        function onDeviceNameChanged(newDeviceName) {
            if (root.expandedWidgetData && root.expandedWidgetData.id === "brightnessSlider") {
                const widgets = SettingsData.controlCenterWidgets || [];
                const newWidgets = widgets.map(w => {
                    if (w.id === "brightnessSlider" && w.instanceId === root.expandedWidgetData.instanceId) {
                        const updatedWidget = Object.assign({}, w);
                        updatedWidget.deviceName = newDeviceName;
                        return updatedWidget;
                    }
                    return w;
                });
                SettingsData.set("controlCenterWidgets", newWidgets);
                if (root.collapseCallback) {
                    root.collapseCallback();
                }
            }
        }
    }

    Connections {
        target: coreDetailLoader.item
        enabled: root.expandedSection.startsWith("diskUsage_")
        ignoreUnknownSignals: true

        function onMountPathChanged(newMountPath) {
            if (root.expandedWidgetData && root.expandedWidgetData.id === "diskUsage") {
                const widgets = SettingsData.controlCenterWidgets || [];
                const newWidgets = widgets.map(w => {
                    if (w.id === "diskUsage" && w.instanceId === root.expandedWidgetData.instanceId) {
                        const updatedWidget = Object.assign({}, w);
                        updatedWidget.mountPath = newMountPath;
                        return updatedWidget;
                    }
                    return w;
                });
                SettingsData.set("controlCenterWidgets", newWidgets);
                if (root.collapseCallback) {
                    root.collapseCallback();
                }
            }
        }
    }

    onExpandedSectionChanged: {
        if (pluginDetailInstance) {
            pluginDetailInstance.destroy();
            pluginDetailInstance = null;
        }
        pluginDetailLoader.active = false;
        coreDetailLoader.active = false;

        if (!root.expandedSection) {
            return;
        }

        if (root.expandedSection.startsWith("builtin_")) {
            const builtinId = root.expandedSection;
            let builtinInstance = null;

            if (builtinId === "builtin_vpn") {
                if (widgetModel?.vpnLoader) {
                    widgetModel.vpnLoader.active = true;
                }
                builtinInstance = widgetModel.vpnBuiltinInstance;
            }
            if (builtinId === "builtin_cups") {
                if (widgetModel?.cupsLoader) {
                    widgetModel.cupsLoader.active = true;
                }
                builtinInstance = widgetModel.cupsBuiltinInstance;
            }

            if (!builtinInstance || !builtinInstance.ccDetailContent) {
                return;
            }

            pluginDetailLoader.sourceComponent = builtinInstance.ccDetailContent;
            pluginDetailLoader.active = parent.height > 0;
            return;
        }

        if (root.expandedSection.startsWith("plugin_")) {
            const pluginId = root.expandedSection.replace("plugin_", "");
            const pluginComponent = PluginService.pluginWidgetComponents[pluginId];
            if (!pluginComponent) {
                return;
            }

            pluginDetailInstance = pluginComponent.createObject(null);
            if (!pluginDetailInstance || !pluginDetailInstance.ccDetailContent) {
                if (pluginDetailInstance) {
                    pluginDetailInstance.destroy();
                    pluginDetailInstance = null;
                }
                return;
            }

            pluginDetailLoader.sourceComponent = pluginDetailInstance.ccDetailContent;
            pluginDetailLoader.active = parent.height > 0;
            return;
        }

        if (root.expandedSection.startsWith("diskUsage_")) {
            coreDetailLoader.sourceComponent = diskUsageDetailComponent;
            coreDetailLoader.active = parent.height > 0;
            return;
        }

        if (root.expandedSection.startsWith("brightnessSlider_")) {
            coreDetailLoader.sourceComponent = brightnessDetailComponent;
            coreDetailLoader.active = parent.height > 0;
            return;
        }

        switch (root.expandedSection) {
        case "network":
        case "wifi":
            coreDetailLoader.sourceComponent = networkDetailComponent;
            break;
        case "bluetooth":
            coreDetailLoader.sourceComponent = bluetoothDetailComponent;
            break;
        case "audioOutput":
            coreDetailLoader.sourceComponent = audioOutputDetailComponent;
            break;
        case "audioInput":
            coreDetailLoader.sourceComponent = audioInputDetailComponent;
            break;
        case "battery":
            coreDetailLoader.sourceComponent = batteryDetailComponent;
            break;
        default:
            return;
        }

        coreDetailLoader.active = parent.height > 0;
    }

    Component {
        id: networkDetailComponent
        NetworkDetail {}
    }

    Component {
        id: bluetoothDetailComponent
        BluetoothDetail {
            id: bluetoothDetail
            onShowCodecSelector: function (device) {
                if (root.bluetoothCodecSelector) {
                    root.bluetoothCodecSelector.show(device);
                    root.bluetoothCodecSelector.codecSelected.connect(function (deviceAddress, codecName) {
                        bluetoothDetail.updateDeviceCodecDisplay(deviceAddress, codecName);
                    });
                }
            }
        }
    }

    Component {
        id: audioOutputDetailComponent
        AudioOutputDetail {}
    }

    Component {
        id: audioInputDetailComponent
        AudioInputDetail {}
    }

    Component {
        id: batteryDetailComponent
        BatteryDetail {}
    }

    Component {
        id: diskUsageDetailComponent
        DiskUsageDetail {
            currentMountPath: root.expandedWidgetData?.mountPath || "/"
            instanceId: root.expandedWidgetData?.instanceId || ""
        }
    }

    Component {
        id: brightnessDetailComponent
        BrightnessDetail {
            initialDeviceName: root.expandedWidgetData?.deviceName || ""
            instanceId: root.expandedWidgetData?.instanceId || ""
            screenName: root.screenName
            screenModel: root.screenModel
        }
    }
}