1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-29 07:52:50 -05:00

weather: fix location override

This commit is contained in:
bbedward
2025-07-15 22:24:50 -04:00
parent 064a914fec
commit f4a33fe97b
3 changed files with 256 additions and 340 deletions

View File

@@ -77,43 +77,42 @@ Rectangle {
} }
} }
Column { Item {
anchors.fill: parent anchors.fill: parent
anchors.margins: theme.spacingS anchors.margins: theme.spacingS
spacing: theme.spacingS
// Show different content based on whether we have active media // Placeholder when no media - centered in entire widget
Item { Column {
width: parent.width anchors.centerIn: parent
height: 60 spacing: theme.spacingS
visible: !activePlayer || !activePlayer.trackTitle || activePlayer.trackTitle === ""
// Placeholder when no media Text {
Column { text: "music_note"
anchors.centerIn: parent font.family: theme.iconFont
spacing: theme.spacingS font.pixelSize: theme.iconSize + 8
visible: !activePlayer || !activePlayer.trackTitle || activePlayer.trackTitle === "" color: Qt.rgba(theme.surfaceText.r, theme.surfaceText.g, theme.surfaceText.b, 0.5)
anchors.horizontalCenter: parent.horizontalCenter
Text {
text: "music_note"
font.family: theme.iconFont
font.pixelSize: theme.iconSize + 8
color: Qt.rgba(theme.surfaceText.r, theme.surfaceText.g, theme.surfaceText.b, 0.5)
anchors.horizontalCenter: parent.horizontalCenter
}
Text {
text: "No Media Playing"
font.pixelSize: theme.fontSizeMedium
color: Qt.rgba(theme.surfaceText.r, theme.surfaceText.g, theme.surfaceText.b, 0.7)
anchors.horizontalCenter: parent.horizontalCenter
}
} }
// Normal media info when playing Text {
Row { text: "No Media Playing"
anchors.fill: parent font.pixelSize: theme.fontSizeMedium
spacing: theme.spacingM color: Qt.rgba(theme.surfaceText.r, theme.surfaceText.g, theme.surfaceText.b, 0.7)
visible: activePlayer && activePlayer.trackTitle && activePlayer.trackTitle !== "" anchors.horizontalCenter: parent.horizontalCenter
}
}
// Active content in a column
Column {
anchors.fill: parent
spacing: theme.spacingS
visible: activePlayer && activePlayer.trackTitle && activePlayer.trackTitle !== ""
// Normal media info when playing
Row {
anchors.fill: parent
spacing: theme.spacingM
// Album Art // Album Art
Rectangle { Rectangle {
@@ -183,10 +182,9 @@ Rectangle {
} }
} }
} }
}
// Progress bar // Progress bar
Item { Item {
id: progressBarContainer id: progressBarContainer
width: parent.width width: parent.width
height: 24 height: 24
@@ -300,10 +298,10 @@ Rectangle {
progressMouseArea.isSeeking = false progressMouseArea.isSeeking = false
} }
} }
} }
// Control buttons - always visible // Control buttons - always visible
Row { Row {
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
spacing: theme.spacingM spacing: theme.spacingM
visible: activePlayer !== null visible: activePlayer !== null
@@ -389,6 +387,7 @@ Rectangle {
onClicked: activePlayer?.next() onClicked: activePlayer?.next()
} }
} }
}
} }
} }
} }

View File

@@ -1,3 +1,4 @@
//NotificationHistoryNative.qml
import QtQuick import QtQuick
import QtQuick.Controls import QtQuick.Controls
import Quickshell import Quickshell

View File

@@ -11,6 +11,13 @@ PanelWindow {
id: settingsPopup id: settingsPopup
property bool settingsVisible: false property bool settingsVisible: false
signal closingPopup()
onSettingsVisibleChanged: {
if (!settingsVisible) {
closingPopup()
}
}
visible: settingsVisible visible: settingsVisible
@@ -381,47 +388,132 @@ PanelWindow {
// Weather Location Search Component // Weather Location Search Component
Item { Item {
id: weatherLocationSearchComponent
width: parent.width width: parent.width
height: searchInputField.height + (searchDropdown.visible ? searchDropdown.height : 0) height: searchInputField.height + (searchDropdown.visible ? searchDropdown.height : 0)
property bool _internalChange: false
property bool isLoading: false
property string helperTextState: "default" // "default", "prompt", "searching", "found", "not_found"
property string currentSearchText: ""
ListModel {
id: searchResultsModel
}
Connections {
target: settingsPopup
function onClosingPopup() {
weatherLocationSearchComponent.resetSearchState()
}
}
function resetSearchState() {
locationSearchTimer.stop()
dropdownHideTimer.stop()
if (locationSearcher.running) {
locationSearcher.running = false;
}
isLoading = false
searchResultsModel.clear()
helperTextState = "default"
}
Timer { Timer {
id: locationSearchTimer id: locationSearchTimer
interval: 500 interval: 500
running: false running: false
repeat: false repeat: false
onTriggered: { onTriggered: {
if (weatherLocationInput.text.length > 2 && !locationSearcher.running) { if (weatherLocationInput.text.length > 2) {
// Clear previous results before starting new search // Stop any running search first
locationSearchResults.searchResults = 0 if (locationSearcher.running) {
locationSearchResults.searchResultNames = new Array() locationSearcher.running = false
locationSearchResults.searchResultQueries = new Array() }
locationSearchResults.isLoading = true
locationSearchResults.currentQuery = weatherLocationInput.text searchResultsModel.clear()
weatherLocationSearchComponent.isLoading = true
weatherLocationSearchComponent.helperTextState = "searching"
const searchLocation = weatherLocationInput.text const searchLocation = weatherLocationInput.text
console.log("=== Starting location search for:", searchLocation) weatherLocationSearchComponent.currentSearchText = searchLocation
// Use OpenStreetMap Nominatim API for location search
const encodedLocation = encodeURIComponent(searchLocation) const encodedLocation = encodeURIComponent(searchLocation)
const curlCommand = `curl -s --connect-timeout 5 --max-time 10 'https://nominatim.openstreetmap.org/search?q=${encodedLocation}&format=json&limit=5&addressdetails=1'` const curlCommand = `curl -s --connect-timeout 5 --max-time 10 'https://nominatim.openstreetmap.org/search?q=${encodedLocation}&format=json&limit=5&addressdetails=1'`
console.log("Running command:", curlCommand)
locationSearcher.command = ["bash", "-c", curlCommand] locationSearcher.command = ["bash", "-c", curlCommand]
locationSearcher.running = true locationSearcher.running = true
} else if (locationSearcher.running) {
console.log("Location search already running, skipping")
} }
} }
} }
Timer { Timer {
id: dropdownHideTimer id: dropdownHideTimer
interval: 1000 // Even longer delay interval: 200 // Short delay to allow clicks
running: false running: false
repeat: false repeat: false
onTriggered: { onTriggered: {
console.log("Hide timer triggered, hiding dropdown") if (!weatherLocationInput.activeFocus && !searchDropdown.hovered) {
searchDropdown.visible = false weatherLocationSearchComponent.resetSearchState()
}
}
}
Process {
id: locationSearcher
command: ["bash", "-c", "echo"]
running: false
stdout: StdioCollector {
onStreamFinished: {
// Only process if this is still the current search
if (weatherLocationSearchComponent.currentSearchText !== weatherLocationInput.text) {
return
}
const raw = text.trim()
weatherLocationSearchComponent.isLoading = false
searchResultsModel.clear()
if (!raw || raw[0] !== "[") {
weatherLocationSearchComponent.helperTextState = "not_found"
return
}
try {
const data = JSON.parse(raw)
if (data.length === 0) {
weatherLocationSearchComponent.helperTextState = "not_found"
return
}
for (let i = 0; i < Math.min(data.length, 5); i++) {
const location = data[i]
if (location.display_name && location.lat && location.lon) {
const parts = location.display_name.split(', ')
let cleanName = parts[0]
if (parts.length > 1) {
const state = parts[parts.length - 2]
if (state && state !== cleanName) {
cleanName += `, ${state}`
}
}
const query = `${location.lat},${location.lon}`
searchResultsModel.append({ "name": cleanName, "query": query })
}
}
weatherLocationSearchComponent.helperTextState = "found"
} catch (e) {
weatherLocationSearchComponent.helperTextState = "not_found"
}
}
}
onExited: (exitCode) => {
weatherLocationSearchComponent.isLoading = false
if (exitCode !== 0) {
searchResultsModel.clear()
weatherLocationSearchComponent.helperTextState = "not_found"
}
} }
} }
@@ -462,22 +554,16 @@ PanelWindow {
selectByMouse: true selectByMouse: true
onTextChanged: { onTextChanged: {
console.log("Text changed to:", text, "length:", text.length) if (weatherLocationSearchComponent._internalChange) return
if (text.length > 2) { if (activeFocus) {
// Don't clear results immediately when starting a new search if (text.length > 2) {
// Only set loading state and restart timer weatherLocationSearchComponent.isLoading = true
locationSearchResults.isLoading = true weatherLocationSearchComponent.helperTextState = "searching"
locationSearchTimer.restart() locationSearchTimer.restart()
searchDropdown.visible = true } else {
console.log("Starting new search, dropdown visible:", searchDropdown.visible) weatherLocationSearchComponent.resetSearchState()
} else { weatherLocationSearchComponent.helperTextState = "prompt"
locationSearchTimer.stop() }
searchDropdown.visible = false
locationSearchResults.searchResults = 0
locationSearchResults.searchResultNames = new Array()
locationSearchResults.searchResultQueries = new Array()
locationSearchResults.isLoading = false
console.log("Text too short, hiding dropdown")
} }
} }
@@ -488,14 +574,14 @@ PanelWindow {
} }
onActiveFocusChanged: { onActiveFocusChanged: {
console.log("Input focus changed:", activeFocus, "dropdown hovered:", searchDropdown.hovered, "aboutToClick:", searchDropdown.aboutToClick, "results count:", locationSearchResults.searchResults) if (activeFocus) {
// Start timer on focus loss, but only if dropdown is visible
if (!activeFocus && !searchDropdown.hovered && !searchDropdown.aboutToClick && searchDropdown.visible) {
console.log("Starting hide timer due to focus loss")
dropdownHideTimer.start()
} else if (activeFocus) {
console.log("Canceling hide timer due to focus gain")
dropdownHideTimer.stop() dropdownHideTimer.stop()
if (weatherLocationInput.text.length <= 2) {
weatherLocationSearchComponent.helperTextState = "prompt"
}
}
else {
dropdownHideTimer.start()
} }
} }
@@ -525,19 +611,19 @@ PanelWindow {
font.family: Theme.iconFont font.family: Theme.iconFont
font.pixelSize: Theme.iconSize - 4 font.pixelSize: Theme.iconSize - 4
color: { color: {
if (locationSearchResults.isLoading) return Theme.surfaceVariantText if (weatherLocationSearchComponent.isLoading) return Theme.surfaceVariantText
if (locationSearchResults.searchResults > 0) return Theme.success || Theme.primary if (searchResultsModel.count > 0) return Theme.success || Theme.primary
if (weatherLocationInput.text.length > 2) return Theme.error if (weatherLocationInput.activeFocus && weatherLocationInput.text.length > 2) return Theme.error
return "transparent" return "transparent"
} }
text: { text: {
if (locationSearchResults.isLoading) return "hourglass_empty" if (weatherLocationSearchComponent.isLoading) return "hourglass_empty"
if (locationSearchResults.searchResults > 0) return "check_circle" if (searchResultsModel.count > 0) return "check_circle"
if (weatherLocationInput.text.length > 2) return "error" if (weatherLocationInput.activeFocus && weatherLocationInput.text.length > 2 && !weatherLocationSearchComponent.isLoading) return "error"
return "" return ""
} }
opacity: weatherLocationInput.text.length > 2 ? 1.0 : 0.0 opacity: (weatherLocationInput.activeFocus && weatherLocationInput.text.length > 2) ? 1.0 : 0.0
Behavior on opacity { Behavior on opacity {
NumberAnimation { NumberAnimation {
@@ -553,164 +639,134 @@ PanelWindow {
Rectangle { Rectangle {
id: searchDropdown id: searchDropdown
width: parent.width width: parent.width
height: Math.min(searchResultsColumn.height + Theme.spacingS * 2, 200) height: Math.min(Math.max(searchResultsModel.count * 38 + Theme.spacingS * 2, 50), 200)
y: searchInputField.height y: searchInputField.height
radius: Theme.cornerRadius radius: Theme.cornerRadius
color: Theme.popupBackground() color: Theme.popupBackground()
border.color: Qt.rgba(Theme.outline.r, Theme.outline.g, Theme.outline.b, 0.3) border.color: Qt.rgba(Theme.outline.r, Theme.outline.g, Theme.outline.b, 0.3)
border.width: 1 border.width: 1
visible: false visible: weatherLocationInput.activeFocus && weatherLocationInput.text.length > 2 && (searchResultsModel.count > 0 || weatherLocationSearchComponent.isLoading)
property bool hovered: false property bool hovered: false
property bool aboutToClick: false
onVisibleChanged: {
console.log("Dropdown visibility changed:", visible)
if (!visible) {
console.log("Dropdown hidden, current results count:", locationSearchResults.searchResults)
}
}
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
hoverEnabled: true hoverEnabled: true
onEntered: { onEntered: {
console.log("Dropdown hovered, canceling hide timer")
parent.hovered = true parent.hovered = true
dropdownHideTimer.stop() dropdownHideTimer.stop()
} }
onExited: { onExited: {
console.log("Dropdown hover exited")
parent.hovered = false parent.hovered = false
if (!weatherLocationInput.activeFocus) { if (!weatherLocationInput.activeFocus) {
console.log("Starting hide timer due to hover exit")
dropdownHideTimer.start() dropdownHideTimer.start()
} }
} }
acceptedButtons: Qt.NoButton acceptedButtons: Qt.NoButton
} }
ScrollView { Item {
anchors.fill: parent anchors.fill: parent
anchors.margins: Theme.spacingS anchors.margins: Theme.spacingS
clip: true
Column { ListView {
id: searchResultsColumn id: searchResultsList
width: parent.width anchors.fill: parent
clip: true
model: searchResultsModel
spacing: 2 spacing: 2
Repeater {
model: locationSearchResults.searchResults
onModelChanged: { delegate: Rectangle {
console.log("Repeater model changed, new count:", model) width: searchResultsList.width
console.log("Names array length:", locationSearchResults.searchResultNames.length)
console.log("Queries array length:", locationSearchResults.searchResultQueries.length)
}
Rectangle {
width: parent.width
height: 36
radius: Theme.cornerRadius
color: resultMouseArea.containsMouse ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.1) : "transparent"
Row {
anchors.fill: parent
anchors.margins: Theme.spacingM
spacing: Theme.spacingS
Text {
font.family: Theme.iconFont
font.pixelSize: Theme.iconSize - 6
color: Theme.surfaceVariantText
text: "place"
anchors.verticalCenter: parent.verticalCenter
}
Text {
text: locationSearchResults.searchResultNames[index] || "Unknown"
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceText
anchors.verticalCenter: parent.verticalCenter
elide: Text.ElideRight
width: parent.width - 30
}
}
MouseArea {
id: resultMouseArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onPressed: {
searchDropdown.aboutToClick = true
}
onClicked: {
const selectedName = locationSearchResults.searchResultNames[index]
const selectedQuery = locationSearchResults.searchResultQueries[index]
// Clear search state first
dropdownHideTimer.stop()
searchDropdown.aboutToClick = false
locationSearchResults.searchResults = 0
locationSearchResults.searchResultNames = new Array()
locationSearchResults.searchResultQueries = new Array()
locationSearchResults.isLoading = false
weatherLocationInput.text = selectedName
searchDropdown.visible = false
Prefs.setWeatherLocationOverride(selectedQuery)
console.log("Selected location:", selectedName, "Query:", selectedQuery)
}
onCanceled: {
searchDropdown.aboutToClick = false
}
}
}
}
// No results message
Text {
width: parent.width
height: 36 height: 36
text: locationSearchResults.isLoading ? "Searching..." : "No locations found" radius: Theme.cornerRadius
font.pixelSize: Theme.fontSizeMedium color: resultMouseArea.containsMouse ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.1) : "transparent"
color: Theme.surfaceVariantText
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter Row {
visible: locationSearchResults.searchResults === 0 && weatherLocationInput.text.length > 2 && !locationSearchResults.isLoading anchors.fill: parent
anchors.margins: Theme.spacingM
spacing: Theme.spacingS
Text {
font.family: Theme.iconFont
font.pixelSize: Theme.iconSize - 6
color: Theme.surfaceVariantText
text: "place"
anchors.verticalCenter: parent.verticalCenter
}
Text {
text: model.name || "Unknown"
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceText
anchors.verticalCenter: parent.verticalCenter
elide: Text.ElideRight
width: parent.width - 30
}
}
MouseArea {
id: resultMouseArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: {
weatherLocationSearchComponent._internalChange = true
const selectedName = model.name
const selectedQuery = model.query
weatherLocationInput.text = selectedName
Prefs.setWeatherLocationOverride(selectedQuery)
weatherLocationSearchComponent.resetSearchState()
weatherLocationInput.focus = false
weatherLocationSearchComponent._internalChange = false
}
}
} }
} }
// Show message when no results
Text {
anchors.centerIn: parent
text: weatherLocationSearchComponent.isLoading ? "Searching..." : "No locations found"
font.pixelSize: Theme.fontSizeMedium
color: Theme.surfaceVariantText
visible: searchResultsList.count === 0 && weatherLocationInput.text.length > 2
}
} }
} }
} }
Text { Text {
text: { text: {
if (locationSearchResults.searchResults > 0) { switch (weatherLocationSearchComponent.helperTextState) {
return `${locationSearchResults.searchResults} location${locationSearchResults.searchResults > 1 ? 's' : ''} found. Click to select.` case "default":
} else if (locationSearchResults.isLoading) { return "Examples: \"New York\", \"Tokyo\", \"44511\""
return "Searching for locations..." case "prompt":
} else if (weatherLocationInput.text.length > 2) { return "Enter 3+ characters to search."
return "No locations found. Try a different search term." case "searching":
} else { return "Searching for locations..."
return "Examples: \"New York\", \"Tokyo\", \"44511\"" case "found":
return `${searchResultsModel.count} location${searchResultsModel.count > 1 ? 's' : ''} found. Click to select.`
case "not_found":
return "No locations found. Try a different search term."
} }
} }
font.pixelSize: Theme.fontSizeSmall font.pixelSize: Theme.fontSizeSmall
color: { color: {
if (locationSearchResults.searchResults > 0) { switch (weatherLocationSearchComponent.helperTextState) {
return Theme.success || Theme.primary case "found":
} else if (locationSearchResults.isLoading) { return Theme.success || Theme.primary
return Theme.surfaceVariantText case "not_found":
} else if (weatherLocationInput.text.length > 2) { return Theme.error
return Theme.error default:
} else { return Theme.surfaceVariantText
return Theme.surfaceVariantText
} }
} }
wrapMode: Text.WordWrap wrapMode: Text.WordWrap
@@ -941,146 +997,6 @@ PanelWindow {
} }
} }
// Weather location search results
QtObject {
id: locationSearchResults
property var searchResults: []
property var searchResultNames: []
property var searchResultQueries: []
property bool isLoading: false
property string currentQuery: ""
}
// Weather location validation
QtObject {
id: locationValidationStatus
property string validationState: "none" // "none", "validating", "valid", "invalid"
property string lastValidatedLocation: ""
property string validatedLocationName: ""
}
Process {
id: locationSearcher
command: ["bash", "-c", "echo"]
running: false
stdout: StdioCollector {
onStreamFinished: {
const raw = text.trim()
locationSearchResults.isLoading = false
console.log("=== Location search response received")
console.log("Response length:", raw.length)
console.log("Response preview:", raw.substring(0, 300))
if (!raw) {
console.log("Empty response from location search")
locationSearchResults.searchResults = 0
locationSearchResults.searchResultNames = new Array()
locationSearchResults.searchResultQueries = new Array()
return
}
if (raw[0] !== "[") {
console.log("Non-JSON array response from location search:", raw)
locationSearchResults.searchResults = 0
locationSearchResults.searchResultNames = new Array()
locationSearchResults.searchResultQueries = new Array()
return
}
try {
const data = JSON.parse(raw)
console.log("Parsed JSON array length:", data.length)
if (data.length === 0) {
console.log("No locations found in search results")
locationSearchResults.searchResults = 0
// Force new empty arrays to trigger QML reactivity
locationSearchResults.searchResultNames = new Array()
locationSearchResults.searchResultQueries = new Array()
console.log("Cleared arrays - Names length:", locationSearchResults.searchResultNames.length, "Queries length:", locationSearchResults.searchResultQueries.length)
return
}
const results = []
for (let i = 0; i < Math.min(data.length, 5); i++) {
const location = data[i]
console.log(`Location ${i}:`, {
display_name: location.display_name,
lat: location.lat,
lon: location.lon,
type: location.type,
class: location.class
})
if (location.display_name && location.lat && location.lon) {
// Create a clean location name from display_name
const parts = location.display_name.split(', ')
let cleanName = parts[0] // Start with the first part
// Add state/region if available and different from first part
if (parts.length > 1) {
const state = parts[parts.length - 2] // Usually the state is second to last
if (state && state !== cleanName) {
cleanName += `, ${state}`
}
}
// Use coordinates as the query for wttr.in (most reliable)
const query = `${location.lat},${location.lon}`
const result = {
"name": cleanName,
"query": query
}
results.push(result)
console.log(`Added result ${i}: name="${cleanName}" query="${query}"`)
} else {
console.log(`Skipped location ${i}: missing required fields`)
}
}
console.log("=== Final results array:", results)
// Create separate arrays for names and queries
const names = []
const queries = []
for (let i = 0; i < results.length; i++) {
names.push(results[i].name)
queries.push(results[i].query)
}
// Set all arrays atomically
locationSearchResults.searchResultNames = names
locationSearchResults.searchResultQueries = queries
locationSearchResults.searchResults = results.length // Just use count for now
console.log("Location search completed:", results.length, "results set")
console.log("Names:", names)
console.log("Queries:", queries)
} catch (e) {
console.log("Location search JSON parse error:", e.message)
console.log("Raw response:", raw.substring(0, 500))
locationSearchResults.searchResults = 0
locationSearchResults.searchResultNames = new Array()
locationSearchResults.searchResultQueries = new Array()
}
}
}
onExited: (exitCode) => {
locationSearchResults.isLoading = false
if (exitCode !== 0) {
console.log("Location search process failed with exit code:", exitCode)
locationSearchResults.searchResults = []
}
}
}
// Keyboard focus and shortcuts // Keyboard focus and shortcuts
FocusScope { FocusScope {
anchors.fill: parent anchors.fill: parent