More fixes for BarTab
This commit is contained in:
parent
8bb6da5e0d
commit
c70b7004c6
1 changed files with 103 additions and 15 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
import QtQuick
|
import QtQuick
|
||||||
import QtQuick.Controls
|
import QtQuick.Controls
|
||||||
import QtQuick.Layouts
|
import QtQuick.Layouts
|
||||||
|
import Qt.labs.folderlistmodel
|
||||||
import qs.Commons
|
import qs.Commons
|
||||||
import qs.Services
|
import qs.Services
|
||||||
import qs.Widgets
|
import qs.Widgets
|
||||||
|
|
@ -584,23 +585,110 @@ ColumnLayout {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Widget list for adding widgets
|
// Dynamic widget discovery using FolderListModel
|
||||||
|
FolderListModel {
|
||||||
|
id: widgetFolderModel
|
||||||
|
folder: Qt.resolvedUrl("../../Bar/Widgets/")
|
||||||
|
nameFilters: ["*.qml"]
|
||||||
|
showDirs: false
|
||||||
|
showFiles: true
|
||||||
|
}
|
||||||
|
|
||||||
ListModel {
|
ListModel {
|
||||||
id: availableWidgets
|
id: availableWidgets
|
||||||
ListElement { key: "SystemMonitor"; name: "SystemMonitor" }
|
}
|
||||||
ListElement { key: "ActiveWindow"; name: "ActiveWindow" }
|
|
||||||
ListElement { key: "MediaMini"; name: "MediaMini" }
|
Component.onCompleted: {
|
||||||
ListElement { key: "Workspace"; name: "Workspace" }
|
discoverWidgets()
|
||||||
ListElement { key: "ScreenRecorderIndicator"; name: "ScreenRecorderIndicator" }
|
}
|
||||||
ListElement { key: "Tray"; name: "Tray" }
|
|
||||||
ListElement { key: "NotificationHistory"; name: "NotificationHistory" }
|
// Automatically discover available widgets from the Widgets directory
|
||||||
ListElement { key: "WiFi"; name: "WiFi" }
|
function discoverWidgets() {
|
||||||
ListElement { key: "Bluetooth"; name: "Bluetooth" }
|
console.log("Discovering widgets...")
|
||||||
ListElement { key: "Battery"; name: "Battery" }
|
console.log("FolderListModel count:", widgetFolderModel.count)
|
||||||
ListElement { key: "Volume"; name: "Volume" }
|
console.log("FolderListModel folder:", widgetFolderModel.folder)
|
||||||
ListElement { key: "Brightness"; name: "Brightness" }
|
|
||||||
ListElement { key: "Clock"; name: "Clock" }
|
availableWidgets.clear()
|
||||||
ListElement { key: "SidePanelToggle"; name: "SidePanelToggle" }
|
|
||||||
|
// Process each .qml file found in the directory
|
||||||
|
for (let i = 0; i < widgetFolderModel.count; i++) {
|
||||||
|
const fileName = widgetFolderModel.get(i, "fileName")
|
||||||
|
console.log("Found file:", fileName)
|
||||||
|
const widgetName = fileName.replace('.qml', '')
|
||||||
|
|
||||||
|
// Skip TrayMenu as it's not a standalone widget
|
||||||
|
if (widgetName !== 'TrayMenu') {
|
||||||
|
console.log("Adding widget:", widgetName)
|
||||||
|
availableWidgets.append({
|
||||||
|
key: widgetName,
|
||||||
|
name: widgetName,
|
||||||
|
icon: getDefaultIcon(widgetName)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("Total widgets added:", availableWidgets.count)
|
||||||
|
|
||||||
|
// If FolderListModel didn't find anything, use fallback
|
||||||
|
if (availableWidgets.count === 0) {
|
||||||
|
console.log("FolderListModel failed, using fallback list")
|
||||||
|
const fallbackWidgets = [
|
||||||
|
"ActiveWindow", "Battery", "Bluetooth", "Brightness", "Clock",
|
||||||
|
"MediaMini", "NotificationHistory", "ScreenRecorderIndicator",
|
||||||
|
"SidePanelToggle", "SystemMonitor", "Tray", "Volume", "WiFi", "Workspace"
|
||||||
|
]
|
||||||
|
|
||||||
|
fallbackWidgets.forEach(widgetName => {
|
||||||
|
availableWidgets.append({
|
||||||
|
key: widgetName,
|
||||||
|
name: widgetName,
|
||||||
|
icon: getDefaultIcon(widgetName)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort alphabetically by name
|
||||||
|
sortWidgets()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort widgets alphabetically
|
||||||
|
function sortWidgets() {
|
||||||
|
const widgets = []
|
||||||
|
for (let i = 0; i < availableWidgets.count; i++) {
|
||||||
|
widgets.push({
|
||||||
|
key: availableWidgets.get(i).key,
|
||||||
|
name: availableWidgets.get(i).name,
|
||||||
|
icon: availableWidgets.get(i).icon
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
widgets.sort((a, b) => a.name.localeCompare(b.name))
|
||||||
|
|
||||||
|
availableWidgets.clear()
|
||||||
|
widgets.forEach(widget => {
|
||||||
|
availableWidgets.append(widget)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get default icon for widget (can be overridden in widget files)
|
||||||
|
function getDefaultIcon(widgetName) {
|
||||||
|
const iconMap = {
|
||||||
|
"ActiveWindow": "web_asset",
|
||||||
|
"Battery": "battery_full",
|
||||||
|
"Bluetooth": "bluetooth",
|
||||||
|
"Brightness": "brightness_6",
|
||||||
|
"Clock": "schedule",
|
||||||
|
"MediaMini": "music_note",
|
||||||
|
"NotificationHistory": "notifications",
|
||||||
|
"ScreenRecorderIndicator": "videocam",
|
||||||
|
"SidePanelToggle": "widgets",
|
||||||
|
"SystemMonitor": "memory",
|
||||||
|
"Tray": "apps",
|
||||||
|
"Volume": "volume_up",
|
||||||
|
"WiFi": "wifi",
|
||||||
|
"Workspace": "dashboard"
|
||||||
|
}
|
||||||
|
return iconMap[widgetName] || "widgets"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue