Wallpaper: cleanup

This commit is contained in:
LemmyCook 2025-08-29 13:04:11 -04:00
parent c37ef867a1
commit db3ea7ed73
3 changed files with 97 additions and 69 deletions

View file

@ -78,6 +78,7 @@ ColumnLayout {
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)
}
// Wallpaper grid container
@ -187,28 +188,37 @@ ColumnLayout {
}
}
// Empty state
}
// Empty state
Rectangle {
anchors.fill: parent
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
ColumnLayout {
anchors.centerIn: parent
spacing: Style.marginM * scaling
id: fallbackColumn
anchors.fill: parent
anchors.margins: Style.marginL * Scaling
Item {
Layout.fillHeight: true
}
NIcon {
text: "folder_open"
font.pointSize: Style.fontSizeL * scaling
font.pointSize: Style.fontSizeXL * scaling
color: Color.mOnSurface
Layout.alignment: Qt.AlignHCenter
}
NText {
text: "No wallpapers found"
text: "No wallpaper found."
color: Color.mOnSurface
font.weight: Style.fontWeightBold
Layout.alignment: Qt.AlignHCenter
@ -216,14 +226,16 @@ ColumnLayout {
NText {
text: "Make sure your wallpaper directory is configured and contains image files."
color: Color.mOnSurface
color: Color.mOnSurfaceVariant
wrapMode: Text.WordWrap
horizontalAlignment: Text.AlignHCenter
Layout.preferredWidth: Style.sliderWidth * 1.5 * scaling
Layout.alignment: Qt.AlignHCenter
}
Item {
Layout.fillHeight: true
}
}
}
}
NDivider {
Layout.fillWidth: true

View file

@ -54,7 +54,7 @@ ColumnLayout {
NTextInput {
label: (modelData.name || "Unknown")
description: `Path to your wallpaper directory for "${(modelData.name || "Unknown")}" monitor`
text: WallpaperService.getMonitorWallpaperDirectory(modelData.name)
text: WallpaperService.getMonitorDirectory(modelData.name)
labelColor: Color.mSecondary
onEditingFinished: WallpaperService.setMonitorWallpaperDirectory(modelData.name, text)
Layout.maximumWidth: 420 * scaling

View file

@ -13,6 +13,7 @@ Singleton {
Logger.log("Wallpaper", "Service started")
}
// All available wallpaper transitions
readonly property ListModel transitionsModel: ListModel {
ListElement {
key: "none"
@ -29,13 +30,20 @@ Singleton {
Connections {
target: Settings.data.wallpaper
function onDirectoryChanged() { console.log("ondirchanged") ; root.listWallpapers() }
function onRandomEnabledChanged() { root.toggleRandomWallpaper() }
function onRandomIntervalSecChanged() { root.restartRandomWallpaperTimer() }
function onDirectoryChanged() {
root.listWallpapers()
}
function onRandomEnabledChanged() {
root.toggleRandomWallpaper()
}
function onRandomIntervalSecChanged() {
root.restartRandomWallpaperTimer()
}
}
// -------------------------------------------------------------------
function geMonitorDefinition(screenName) {
// Get specific monitor wallpaper data
function getMonitorConfig(screenName) {
var monitors = Settings.data.wallpaper.monitors
if (monitors !== undefined) {
for (var i = 0; i < monitors.length; i++) {
@ -47,42 +55,36 @@ Singleton {
}
// -------------------------------------------------------------------
function getMonitorWallpaperDirectory(screenName) {
var monitor = geMonitorDefinition(screenName)
if (monitor !== undefined) {
// Get specific monitor directory
function getMonitorDirectory(screenName) {
var monitor = getMonitorConfig(screenName)
if (monitor !== undefined && monitor.directory !== undefined) {
return monitor.directory
}
// Fall back to the main/single directory
return Settings.data.wallpaper.directory
}
// -------------------------------------------------------------------
function setMonitorWallpaperDirectory(screenName, directory) {
var monitor = geMonitorDefinition(screenName)
// Set specific monitor directory
function setMonitorDirectory(screenName, directory) {
var monitor = getMonitorConfig(screenName)
if (monitor !== undefined) {
monitor.directory = directory
return
} else {
Settings.data.wallpaper.monitors.push({
"name": screenName,
"directory": directory,
"wallpaper": ""
})
}
Settings.data.wallpaper.monitors.push({
"name": screenName,
"directory": directory,
"wallpaper": ""
})
}
// -------------------------------------------------------------------
function listWallpapers() {
Logger.log("Wallpaper", "Listing wallpapers")
scanning = true
wallpaperList = []
// Set the folder directly to avoid model reset issues
folderModel.folder = "file://" + (Settings.data.wallpaper.directory !== undefined ? Settings.data.wallpaper.directory : "")
}
// -------------------------------------------------------------------
// Get specific monitor wallpaper
function getWallpaper(screenName) {
// Logger.log("Wallpaper", "getWallpaper on", screenName)
var monitor = geMonitorDefinition(screenName)
var monitor = getMonitorConfig(screenName)
if ((monitor !== undefined) && (monitor["wallpaper"] !== undefined)) {
return monitor["wallpaper"]
}
@ -91,18 +93,18 @@ Singleton {
// -------------------------------------------------------------------
function changeWallpaper(screenName, path) {
Logger.log("Changing wallpaper")
if (screenName !== undefined) {
setCurrentWallpaper(screenName, path)
setWallpaper(screenName, path)
} else {
// If no screenName specified change for all screens
for (var i = 0; i < Quickshell.screens.length; i++) {
setCurrentWallpaper(Quickshell.screens[i].name, path, false)
setWallpaper(Quickshell.screens[i].name, path)
}
}
}
// -------------------------------------------------------------------
function setCurrentWallpaper(screenName, path) {
function setWallpaper(screenName, path) {
if (path === "" || path === undefined) {
return
}
@ -124,7 +126,7 @@ Singleton {
wallpaperChanged = true
Settings.data.wallpaper.monitors.push({
"name": screenName,
"directory": Settings.data.wallpaper.directory,
"directory": getMonitorDirectory(screenName),
"wallpaper": path
})
}
@ -142,13 +144,16 @@ Singleton {
// -------------------------------------------------------------------
function setRandomWallpaper() {
Logger.log("Wallpaper", "setRandomWallpaper");
Logger.log("Wallpaper", "setRandomWallpaper")
for (var i = 0; i < Quickshell.screens.length; i++) {
var screenName = Quickshell.screens[i].name
// TODO one list per monitor
var randomIndex = Math.floor(Math.random() * wallpaperList.length)
var randomPath = wallpaperList[randomIndex]
setCurrentWallpaper(screenName, randomPath)
var wallpaperList = getWallpaperList(screenName)
if (wallpaperList.length > 0) {
var randomIndex = Math.floor(Math.random() * wallpaperList.length)
var randomPath = wallpaperList[randomIndex]
setCurrentWallpaper(screenName, randomPath)
}
}
}
@ -171,6 +176,17 @@ Singleton {
}
}
// -------------------------------------------------------------------
function listWallpapers() {
if (!Settings.isLoaded) {
return
}
// TODO
Logger.log("Wallpaper", "Listing wallpapers for all monitors")
scanning = true
}
// -------------------------------------------------------------------
// -------------------------------------------------------------------
// -------------------------------------------------------------------
@ -183,23 +199,23 @@ 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)
}
}
}
// 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)
// }
// }
// }
}