Skip to content

Instantly share code, notes, and snippets.

@Zren
Created January 15, 2020 19:53
Show Gist options
  • Select an option

  • Save Zren/6d8fe1d91049996253234c4d619c7a9b to your computer and use it in GitHub Desktop.

Select an option

Save Zren/6d8fe1d91049996253234c4d619c7a9b to your computer and use it in GitHub Desktop.
import QtQuick 2.9
import org.kde.plasma.private.weather 1.0
import org.kde.plasma.core 2.0 as PlasmaCore
Item {
id: root
readonly property string weatherSource: "envcan|weather|Toronto, ON"
readonly property int updateInterval: 30
PlasmaCore.DataSource {
id: weatherDataSource
readonly property var currentData: data[weatherSource]
engine: "weather"
connectedSources: weatherSource
interval: updateInterval * 60 * 1000
}
readonly property var weatherData: weatherDataSource.currentData || {}
readonly property int invalidUnit: -1 //TODO: make KUnitConversion::InvalidUnit usable here
function getNumberOrString(key) {
var number = weatherData[key]
return (typeof number !== "undefined") && (number !== "") ? number : null
}
function getDetailsItemAndUnits(valueKey, reportUnitKey) {
var reportUnit = weatherData[reportUnitKey] || invalidUnit
var displayUnit = reportUnit // TODO: Check for user locale/configured unit
var value = getNumberOrString(valueKey)
if (value) {
if (reportUnit !== invalidUnit) {
value = Util.valueToDisplayString(displayUnit, value, reportUnit, 1)
}
return value
} else {
return null
}
}
Text {
anchors.fill: parent
text : getDetailsItemAndUnits("Temperature", "Temperature Unit")
color:"black"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment