diff --git a/Modules/SettingsPanel/Tabs/WallpaperSelectorTab.qml b/Modules/SettingsPanel/Tabs/WallpaperSelectorTab.qml index 2664631..f74e64e 100644 --- a/Modules/SettingsPanel/Tabs/WallpaperSelectorTab.qml +++ b/Modules/SettingsPanel/Tabs/WallpaperSelectorTab.qml @@ -67,32 +67,34 @@ ColumnLayout { icon: "refresh" tooltipText: "Refresh wallpaper list" onClicked: { - WallpaperService.listWallpapers() + WallpaperService.refreshWallpapersList() } Layout.alignment: Qt.AlignVCenter | Qt.AlignRight } } + property list wallpapersList: WallpaperService.getWallpapersList(screen.name) + NToggle { label: "Assign selection to all monitors" description: "Set selected wallpaper on all monitors at once." checked: Settings.data.wallpaper.setWallpaperOnAllMonitors onToggled: checked => Settings.data.wallpaper.setWallpaperOnAllMonitors = checked - visible: (WallpaperService.wallpaperList.length > 0) + visible: (wallpapersList.length > 0) } // Wallpaper grid container Item { Layout.fillWidth: true Layout.preferredHeight: { - return Math.ceil(WallpaperService.wallpaperList.length / wallpaperGridView.columns) * wallpaperGridView.cellHeight + return Math.ceil(wallpapersList.length / wallpaperGridView.columns) * wallpaperGridView.cellHeight } GridView { id: wallpaperGridView anchors.fill: parent clip: true - model: WallpaperService.wallpaperList + model: wallpapersList boundsBehavior: Flickable.StopAtBounds flickableDirection: Flickable.AutoFlickDirection @@ -187,54 +189,52 @@ ColumnLayout { } } } - - } // Empty state - Rectangle { - color: Color.mSurface - radius: Style.radiusM * scaling - border.color: Color.mOutline - border.width: Math.max(1, Style.borderS * scaling) - visible: WallpaperService.wallpaperList.length === 0 && !WallpaperService.scanning - Layout.fillWidth: true - Layout.preferredHeight: 130 * scaling + Rectangle { + color: Color.mSurface + radius: Style.radiusM * scaling + border.color: Color.mOutline + border.width: Math.max(1, Style.borderS * scaling) + visible: wallpapersList.length === 0 && !WallpaperService.scanning + Layout.fillWidth: true + Layout.preferredHeight: 130 * scaling - ColumnLayout { - id: fallbackColumn - anchors.fill: parent + ColumnLayout { + id: fallbackColumn + anchors.fill: parent - Item { - Layout.fillHeight: true - } + Item { + Layout.fillHeight: true + } - NIcon { - text: "folder_open" - font.pointSize: Style.fontSizeXL * scaling - color: Color.mOnSurface - Layout.alignment: Qt.AlignHCenter - } + NIcon { + text: "folder_open" + font.pointSize: Style.fontSizeXL * scaling + color: Color.mOnSurface + Layout.alignment: Qt.AlignHCenter + } - NText { - text: "No wallpaper found." - color: Color.mOnSurface - font.weight: Style.fontWeightBold - Layout.alignment: Qt.AlignHCenter - } + NText { + text: "No wallpaper found." + color: Color.mOnSurface + font.weight: Style.fontWeightBold + Layout.alignment: Qt.AlignHCenter + } - NText { - text: "Make sure your wallpaper directory is configured and contains image files." - color: Color.mOnSurfaceVariant - wrapMode: Text.WordWrap - Layout.alignment: Qt.AlignHCenter - } + NText { + text: "Make sure your wallpaper directory is configured and contains image files." + color: Color.mOnSurfaceVariant + wrapMode: Text.WordWrap + Layout.alignment: Qt.AlignHCenter + } - Item { - Layout.fillHeight: true - } + Item { + Layout.fillHeight: true } } + } NDivider { Layout.fillWidth: true diff --git a/Modules/SettingsPanel/Tabs/WallpaperTab.qml b/Modules/SettingsPanel/Tabs/WallpaperTab.qml index f1e2b6f..18b82be 100644 --- a/Modules/SettingsPanel/Tabs/WallpaperTab.qml +++ b/Modules/SettingsPanel/Tabs/WallpaperTab.qml @@ -56,7 +56,7 @@ ColumnLayout { description: `Path to your wallpaper directory for "${(modelData.name || "Unknown")}" monitor` text: WallpaperService.getMonitorDirectory(modelData.name) labelColor: Color.mSecondary - onEditingFinished: WallpaperService.setMonitorWallpaperDirectory(modelData.name, text) + onEditingFinished: WallpaperService.setMonitorDirectory(modelData.name, text) Layout.maximumWidth: 420 * scaling } } diff --git a/Services/WallpaperService.qml b/Services/WallpaperService.qml index dd44f86..3fe637f 100644 --- a/Services/WallpaperService.qml +++ b/Services/WallpaperService.qml @@ -25,13 +25,13 @@ Singleton { } } - property var wallpaperList: [] + property var wallpaperLists: ({}) property bool scanning: false Connections { target: Settings.data.wallpaper function onDirectoryChanged() { - root.listWallpapers() + root.refreshWallpapersList() } function onRandomEnabledChanged() { root.toggleRandomWallpaper() @@ -110,15 +110,15 @@ Singleton { } if (screenName === undefined) { - Logger.warn("Wallpaper", "setCurrentWallpaper", "no screen specified") + Logger.warn("Wallpaper", "setWallpaper", "no screen specified") return } - Logger.log("Wallpaper", "setCurrentWallpaper on", screenName, ": ", path) + Logger.log("Wallpaper", "setWallpaper on", screenName, ": ", path) var wallpaperChanged = false - var monitor = geMonitorDefinition(screenName) + var monitor = getMonitorConfig(screenName) if (monitor !== undefined) { wallpaperChanged = (monitor["wallpaper"] !== path) monitor["wallpaper"] = path @@ -152,7 +152,7 @@ Singleton { if (wallpaperList.length > 0) { var randomIndex = Math.floor(Math.random() * wallpaperList.length) var randomPath = wallpaperList[randomIndex] - setCurrentWallpaper(screenName, randomPath) + setWallpaper(screenName, randomPath) } } } @@ -177,13 +177,21 @@ Singleton { } // ------------------------------------------------------------------- - function listWallpapers() { + function getWallpapersList(screenName) { + if (screenName != undefined && wallpaperLists[screenName] != undefined) { + return wallpaperLists[screenName] + } + return [] + } + + // ------------------------------------------------------------------- + function refreshWallpapersList() { if (!Settings.isLoaded) { return } // TODO - Logger.log("Wallpaper", "Listing wallpapers for all monitors") + Logger.log("Wallpaper", "refreshWallpapersList") scanning = true } @@ -199,23 +207,34 @@ Singleton { triggeredOnStart: false } - // FolderListModel { - // id: folderModel - // nameFilters: ["*.jpg", "*.jpeg", "*.png", "*.gif", "*.pnm", "*.bmp"] - // showDirs: false - // sortField: FolderListModel.Name - // onStatusChanged: { - // if (status === FolderListModel.Ready) { - // var files = [] - // for (var i = 0; i < count; i++) { - // var directory = (Settings.data.wallpaper.directory !== undefined ? Settings.data.wallpaper.directory : "") - // var filepath = directory + "/" + get(i, "fileName") - // files.push(filepath) - // } - // wallpaperList = files - // scanning = false - // Logger.log("Wallpaper", "List refreshed, count:", wallpaperList.length) - // } - // } - // } + // Instantiator (not Repeater) to create FolderListModel for each monitor + Instantiator { + model: Quickshell.screens + + delegate: FolderListModel { + property string screenName: modelData.name + + folder: "file://" + root.getMonitorDirectory(screenName) + nameFilters: ["*.jpg", "*.jpeg", "*.png", "*.gif", "*.pnm", "*.bmp"] + showDirs: false + sortField: FolderListModel.Name + + onStatusChanged: { + if (status === FolderListModel.Ready) { + var files = [] + for (var i = 0; i < count; i++) { + var directory = root.getMonitorDirectory(screenName) + var filepath = directory + "/" + get(i, "fileName") + files.push(filepath) + } + + var lists = root.wallpaperLists + lists[screenName] = files + root.wallpaperLists = lists + + Logger.log("Wallpaper", "List refreshed for", screenName, "count:", files.length) + } + } + } + } }