diff --git a/applets/weather/package/contents/config/main.xml b/applets/weather/package/contents/config/main.xml new file mode 100644 --- /dev/null +++ b/applets/weather/package/contents/config/main.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + 30 + + + + + + true + + + false + + + false + + + false + + + false + + + + + + + + 0 + + + + 0 + + + + 0 + + + + 0 + + + + + + false + + + + diff --git a/applets/weather/package/contents/ui/CompactRepresentation.qml b/applets/weather/package/contents/ui/CompactRepresentation.qml --- a/applets/weather/package/contents/ui/CompactRepresentation.qml +++ b/applets/weather/package/contents/ui/CompactRepresentation.qml @@ -29,8 +29,8 @@ property var observationModel readonly property bool vertical: (plasmoid.formFactor == PlasmaCore.Types.Vertical) - readonly property bool showTemperature: plasmoid.nativeInterface.temperatureShownInCompactMode && - !plasmoid.nativeInterface.needsToBeSquare + readonly property bool showTemperature: plasmoid.configuration.temperatureShownInCompactMode && + !plasmoid.configuration.needsToBeSquare Loader { id: loader diff --git a/applets/weather/package/contents/ui/DisplayUnits.qml b/applets/weather/package/contents/ui/DisplayUnits.qml new file mode 100644 --- /dev/null +++ b/applets/weather/package/contents/ui/DisplayUnits.qml @@ -0,0 +1,51 @@ +import QtQuick 2.0 + +QtObject { + // https://doc.qt.io/qt-5/qml-qtqml-locale.html#measurementSystem-prop + readonly property bool localeUsesMetric: Qt.locale().measurementSystem == Locale.MetricSystem + + readonly property int temperatureUnitId: { + if (plasmoid.configuration.temperatureUnitId === 0) { // Use locale default + if (localeUsesMetric) { + return 6001 // Celcius + } else { + return 6002 // Fahrenheit + } + } else { + return plasmoid.configuration.temperatureUnitId + } + } + readonly property int speedUnitId: { + if (plasmoid.configuration.speedUnitId === 0) { // Use locale default + if (localeUsesMetric) { + return 9000 // MeterPerSecond + } else { + return 9002 // MilePerHour + } + } else { + return plasmoid.configuration.speedUnitId + } + } + readonly property int pressureUnitId: { + if (plasmoid.configuration.pressureUnitId === 0) { // Use locale default + if (localeUsesMetric) { + return 5008 // Hectopascal + } else { + return 5028 // InchesOfMercury + } + } else { + return plasmoid.configuration.pressureUnitId + } + } + readonly property int visibilityUnitId: { + if (plasmoid.configuration.visibilityUnitId === 0) { // Use locale default + if (localeUsesMetric) { + return 2007 // Kilometer + } else { + return 2024 // Mile + } + } else { + return plasmoid.configuration.visibilityUnitId + } + } +} diff --git a/applets/weather/package/contents/ui/config/ConfigAppearance.qml b/applets/weather/package/contents/ui/config/ConfigAppearance.qml --- a/applets/weather/package/contents/ui/config/ConfigAppearance.qml +++ b/applets/weather/package/contents/ui/config/ConfigAppearance.qml @@ -26,35 +26,13 @@ ColumnLayout { id: displayConfigPage - readonly property bool canShowMoreInCompactMode: !plasmoid.nativeInterface.needsToBeSquare - - signal configurationChanged - - function saveConfig() { - var config = {}; - - config.showTemperatureInTooltip = showTemperatureInTooltipCheckBox.checked; - config.showWindInTooltip = showWindInTooltipCheckBox.checked; - config.showPressureInTooltip = showPressureInTooltipCheckBox.checked; - config.showHumidityInTooltip = showHumidityInTooltipCheckBox.checked; - - config.showTemperatureInCompactMode = showTemperatureInCompactModeCheckBox.checked; - - plasmoid.nativeInterface.saveConfig(config); - plasmoid.nativeInterface.configChanged(); - } - - Component.onCompleted: { - var config = plasmoid.nativeInterface.configValues(); - - showTemperatureInTooltipCheckBox.checked = config.showTemperatureInTooltip; - showWindInTooltipCheckBox.checked = config.showWindInTooltip; - showPressureInTooltipCheckBox.checked = config.showPressureInTooltip; - showHumidityInTooltipCheckBox.checked = config.showHumidityInTooltip; - - showTemperatureInCompactModeCheckBox.checked = config.showTemperatureInCompactMode; - } + property alias cfg_showTemperatureInTooltip: showTemperatureInTooltipCheckBox.checked + property alias cfg_showWindInTooltip: showWindInTooltipCheckBox.checked + property alias cfg_showPressureInTooltip: showPressureInTooltipCheckBox.checked + property alias cfg_showHumidityInTooltip: showHumidityInTooltipCheckBox.checked + property alias cfg_showTemperatureInCompactMode: showTemperatureInCompactModeCheckBox.checked + readonly property bool canShowMoreInCompactMode: !plasmoid.configuration.needsToBeSquare QtControls1.GroupBox { Layout.fillWidth: true @@ -81,7 +59,6 @@ enabled: canShowMoreInCompactMode text: i18nc("@option:check", "Show temperature") - onCheckedChanged: displayConfigPage.configurationChanged(); } QtControls.Label { @@ -98,7 +75,6 @@ Layout.column: 1 text: i18nc("@option:check", "Show temperature") - onCheckedChanged: displayConfigPage.configurationChanged(); } QtControls.CheckBox { @@ -108,7 +84,6 @@ Layout.column: 1 text: i18nc("@option:check", "Show wind") - onCheckedChanged: displayConfigPage.configurationChanged(); } QtControls.CheckBox { @@ -118,7 +93,6 @@ Layout.column: 1 text: i18nc("@option:check", "Show pressure") - onCheckedChanged: displayConfigPage.configurationChanged(); } QtControls.CheckBox { @@ -128,7 +102,6 @@ Layout.column: 1 text: i18nc("@option:check", "Show humidity") - onCheckedChanged: displayConfigPage.configurationChanged(); } } } diff --git a/applets/weather/package/contents/ui/config/ConfigUnits.qml b/applets/weather/package/contents/ui/config/ConfigUnits.qml --- a/applets/weather/package/contents/ui/config/ConfigUnits.qml +++ b/applets/weather/package/contents/ui/config/ConfigUnits.qml @@ -21,39 +21,35 @@ import org.kde.plasma.private.weather 1.0 +import ".." // DisplayUnits ColumnLayout { id: unitsConfigPage signal configurationChanged - function saveConfig() { - var config = {}; + DisplayUnits { id: displayUnits } - config.temperatureUnitId = + function saveConfig() { + plasmoid.configuration.temperatureUnitId = TemperatureUnitListModel.unitIdForListIndex(temperatureComboBox.currentIndex); - config.pressureUnitId = + plasmoid.configuration.pressureUnitId = PressureUnitListModel.unitIdForListIndex(pressureComboBox.currentIndex); - config.windSpeedUnitId = + plasmoid.configuration.windSpeedUnitId = WindSpeedUnitListModel.unitIdForListIndex(windSpeedComboBox.currentIndex); - config.visibilityUnitId = + plasmoid.configuration.visibilityUnitId = VisibilityUnitListModel.unitIdForListIndex(visibilityComboBox.currentIndex); - - plasmoid.nativeInterface.saveConfig(config); - plasmoid.nativeInterface.configChanged(); } Component.onCompleted: { - var config = plasmoid.nativeInterface.configValues(); - temperatureComboBox.currentIndex = - TemperatureUnitListModel.listIndexForUnitId(config.temperatureUnitId); + TemperatureUnitListModel.listIndexForUnitId(displayUnits.temperatureUnitId); pressureComboBox.currentIndex = - PressureUnitListModel.listIndexForUnitId(config.pressureUnitId); + PressureUnitListModel.listIndexForUnitId(displayUnits.pressureUnitId); windSpeedComboBox.currentIndex = - WindSpeedUnitListModel.listIndexForUnitId(config.windSpeedUnitId); + WindSpeedUnitListModel.listIndexForUnitId(displayUnits.speedUnitId); visibilityComboBox.currentIndex = - VisibilityUnitListModel.listIndexForUnitId(config.visibilityUnitId); + VisibilityUnitListModel.listIndexForUnitId(displayUnits.visibilityUnitId); } diff --git a/applets/weather/package/contents/ui/config/ConfigWeatherStation.qml b/applets/weather/package/contents/ui/config/ConfigWeatherStation.qml --- a/applets/weather/package/contents/ui/config/ConfigWeatherStation.qml +++ b/applets/weather/package/contents/ui/config/ConfigWeatherStation.qml @@ -28,39 +28,12 @@ ColumnLayout { id: weatherStationConfigPage - property string source - - signal configurationChanged - - function saveConfig() { - var config = { - services: stationPicker.selectedServices, - source: source, - updateInterval: updateIntervalSpin.value - }; - - plasmoid.nativeInterface.saveConfig(config); - plasmoid.nativeInterface.configChanged(); - } - - - Component.onCompleted: { - var config = plasmoid.nativeInterface.configValues(); - - stationPicker.selectedServices = config.services; - - source = config.source; - - updateIntervalSpin.value = config.updateInterval; - } + property alias cfg_services: stationPicker.selectedServices + property alias cfg_source: stationPicker.source + property alias cfg_updateInterval: updateIntervalSpin.value WeatherStationPickerDialog { id: stationPicker - - onAccepted: { - weatherStationConfigPage.source = source; - weatherStationConfigPage.configurationChanged(); - } } GridLayout { @@ -84,7 +57,7 @@ elide: Text.ElideRight text: { - var sourceDetails = source.split('|'); + var sourceDetails = cfg_source.split('|'); if (sourceDetails.length > 2) { return i18nc("A weather station location and the weather service it comes from", "%1 (%2)", sourceDetails[2], sourceDetails[0]); @@ -117,7 +90,6 @@ stepSize: 5 minimumValue: 30 maximumValue: 3600 - onValueChanged: weatherStationConfigPage.configurationChanged(); } } diff --git a/applets/weather/package/contents/ui/config/WeatherStationPicker.qml b/applets/weather/package/contents/ui/config/WeatherStationPicker.qml --- a/applets/weather/package/contents/ui/config/WeatherStationPicker.qml +++ b/applets/weather/package/contents/ui/config/WeatherStationPicker.qml @@ -77,7 +77,7 @@ onToggled: { model.checked = checked; checked = Qt.binding(function() { return model.checked; }); - weatherStationConfigPage.configurationChanged(); + // weatherStationConfigPage.configurationChanged(); } } onObjectAdded: serviceSelectionMenu.insertItem(index, object) diff --git a/applets/weather/package/contents/ui/main.qml b/applets/weather/package/contents/ui/main.qml --- a/applets/weather/package/contents/ui/main.qml +++ b/applets/weather/package/contents/ui/main.qml @@ -25,12 +25,18 @@ Item { id: root - readonly property string weatherSource: plasmoid.nativeInterface.source - readonly property int updateInterval: plasmoid.nativeInterface.updateInterval - readonly property int displayTemperatureUnit: plasmoid.nativeInterface.displayTemperatureUnit - readonly property int displaySpeedUnit: plasmoid.nativeInterface.displaySpeedUnit - readonly property int displayPressureUnit: plasmoid.nativeInterface.displayPressureUnit - readonly property int displayVisibilityUnit: plasmoid.nativeInterface.displayVisibilityUnit + // readonly property string weatherSource: 'bbcukmet|weather|City of London, Greater London|2643741' + // readonly property string weatherSource: 'envcan|weather|Toronto, ON' + // readonly property string weatherSource: 'noaa|weather|New York City, Central Park, NY' + // readonly property string weatherSource: 'wettercom|weather|London, London, GB|GB0KI0101;London' + + readonly property string weatherSource: plasmoid.configuration.source + readonly property int updateInterval: plasmoid.configuration.updateInterval + DisplayUnits { id: displayUnits } + readonly property alias displayTemperatureUnit: displayUnits.temperatureUnitId + readonly property alias displaySpeedUnit: displayUnits.speedUnitId + readonly property alias displayPressureUnit: displayUnits.pressureUnitId + readonly property alias displayVisibilityUnit: displayUnits.visibilityUnitId property bool connectingToSource: false readonly property bool needsConfiguration: !generalModel.location && !connectingToSource @@ -393,14 +399,14 @@ return ""; } var tooltips = []; - var temperature = plasmoid.nativeInterface.temperatureShownInTooltip ? observationModel.temperature : null; + var temperature = plasmoid.configuration.temperatureShownInTooltip ? observationModel.temperature : null; if (observationModel.conditions && temperature) { tooltips.push(i18nc("weather condition + temperature", "%1 %2", observationModel.conditions, temperature)); } else if (observationModel.conditions || temperature) { tooltips.push(observationModel.conditions || temperature); } - if (plasmoid.nativeInterface.windShownInTooltip && observationModel.windSpeed) { + if (plasmoid.configuration.windShownInTooltip && observationModel.windSpeed) { if (observationModel.windDirection) { if (observationModel.windGust) { tooltips.push(i18nc("winddirection windspeed (windgust)", "%1 %2 (%3)", @@ -413,7 +419,7 @@ tooltips.push(observationModel.windSpeed); } } - if (plasmoid.nativeInterface.pressureShownInTooltip && observationModel.pressure) { + if (plasmoid.configuration.pressureShownInTooltip && observationModel.pressure) { if (observationModel.pressureTendency) { tooltips.push(i18nc("pressure (tendency)", "%1 (%2)", observationModel.pressure, observationModel.pressureTendency)); @@ -421,7 +427,7 @@ tooltips.push(observationModel.pressure); } } - if (plasmoid.nativeInterface.humidityShownInTooltip && observationModel.humidity) { + if (plasmoid.configuration.humidityShownInTooltip && observationModel.humidity) { tooltips.push(i18n("Humidity: %1", observationModel.humidity)); } @@ -439,10 +445,41 @@ observationModel: root.observationModel } + function migrateKey(nativeKey, configKey) { + plasmoid.configuration[configKey] = plasmoid.nativeInterface[nativeKey] + console.log('[weather] migrated', configKey, plasmoid.configuration[configKey], '(nativeInterface: ', plasmoid.nativeInterface[nativeKey], ')'); + } + function migrateFromNativeInterface() { + migrateKey('source', 'source') + migrateKey('updateInterval', 'updateInterval') + migrateKey('displayTemperatureUnit', 'temperatureUnitId') + migrateKey('displaySpeedUnit', 'speedUnitId') + migrateKey('displayPressureUnit', 'pressureUnitId') + migrateKey('displayVisibilityUnit', 'visibilityUnitId') + migrateKey('temperatureShownInTooltip', 'showTemperatureInTooltip') + migrateKey('windShownInTooltip', 'showWindInTooltip') + migrateKey('pressureShownInTooltip', 'showPressureInTooltip') + migrateKey('humidityShownInTooltip', 'showHumidityInTooltip') + migrateKey('temperatureShownInCompactMode', 'showTemperatureInCompactMode') + + var config = plasmoid.nativeInterface.configValues(); + plasmoid.configuration.services = config.services; + console.log('[weather] migrated', 'services', plasmoid.configuration.services, '(nativeInterface: ', config.services, ')'); + + // Migration finished + plasmoid.nativeInterface.source = "" + } + Component.onCompleted: { + // Migrate 5.15 and below => 5.16 and above + // TODO: Remove migration code after Plasma 5.19 (version after next Plasma LTS) + if (plasmoid.nativeInterface && plasmoid.nativeInterface.source) { + migrateFromNativeInterface() + } + // workaround for missing note about being in systray or similar (kde bug #388995) // guess from cointainer structure data and make available to config page - plasmoid.nativeInterface.needsToBeSquare = + plasmoid.configuration.needsToBeSquare = (plasmoid.parent !== null && ((plasmoid.parent.pluginName === 'org.kde.plasma.private.systemtray' || plasmoid.parent.objectName === 'taskItemContainer')));