diff --git a/daemon/daemon.pro b/daemon/daemon.pro index aa20d9c4..1e2699aa 100644 --- a/daemon/daemon.pro +++ b/daemon/daemon.pro @@ -131,6 +131,7 @@ SOURCES += \ src/services/infinitimemotionservice.cpp \ src/services/infinitimenavservice.cpp \ src/services/infinitimeweatherservice.cpp \ + src/services/pinetimesimpleweatherservice.cpp \ src/services/pinetimemusicservice.cpp \ src/services/uartservice.cpp \ src/typeconversion.cpp \ @@ -205,6 +206,7 @@ HEADERS += \ src/services/infinitimemotionservice.h \ src/services/infinitimenavservice.h \ src/services/infinitimeweatherservice.h \ + src/services/pinetimesimpleweatherservice.h \ src/services/pinetimemusicservice.h \ src/services/uartservice.h \ src/services/immediatealertservice.h \ diff --git a/daemon/src/devices/banglejsdevice.cpp b/daemon/src/devices/banglejsdevice.cpp index 89d0ae80..46186a24 100644 --- a/daemon/src/devices/banglejsdevice.cpp +++ b/daemon/src/devices/banglejsdevice.cpp @@ -195,10 +195,10 @@ void BangleJSDevice::sendWeather(CurrentWeather *weather) QJsonObject o; o.insert("t", "weather"); o.insert("temp", weather->temperature()); - o.insert("hum", 0); //TODO we dont have this + o.insert("hum", weather->humidity()); o.insert("txt", weather->description()); - o.insert("wind", 0); //TODO we dont have this - o.insert("wdir", ""); // TODO we dont have this + o.insert("wind", weather->windSpeed()); + o.insert("wdir", weather->windDeg()); o.insert("loc", weather->city()->name()); uart->txJson(o); diff --git a/daemon/src/devices/pinetimejfdevice.cpp b/daemon/src/devices/pinetimejfdevice.cpp index ee0426a5..bdde09e0 100644 --- a/daemon/src/devices/pinetimejfdevice.cpp +++ b/daemon/src/devices/pinetimejfdevice.cpp @@ -11,6 +11,7 @@ #include "hrmservice.h" #include "infinitimemotionservice.h" #include "infinitimeweatherservice.h" +#include "pinetimesimpleweatherservice.h" #include "adafruitblefsservice.h" #include "batteryservice.h" #include "amazfishconfig.h" @@ -154,6 +155,8 @@ void PinetimeJFDevice::parseServices() addService(HRMService::UUID_SERVICE_HRM, new HRMService(path, this)); } else if (uuid == InfiniTimeMotionService::UUID_SERVICE_MOTION && !service(InfiniTimeMotionService::UUID_SERVICE_MOTION)) { addService(InfiniTimeMotionService::UUID_SERVICE_MOTION, new InfiniTimeMotionService(path, this)); + } else if (uuid == PineTimeSimpleWeatherService::UUID_SERVICE_SIMPLE_WEATHER && !service(PineTimeSimpleWeatherService::UUID_SERVICE_SIMPLE_WEATHER)) { + addService(PineTimeSimpleWeatherService::UUID_SERVICE_SIMPLE_WEATHER, new PineTimeSimpleWeatherService(path, this)); } else if (uuid == InfiniTimeWeatherService::UUID_SERVICE_WEATHER && !service(InfiniTimeWeatherService::UUID_SERVICE_WEATHER)) { addService(InfiniTimeWeatherService::UUID_SERVICE_WEATHER, new InfiniTimeWeatherService(path, this)); } else if (uuid == AdafruitBleFsService::UUID_SERVICE_FS && !service(AdafruitBleFsService::UUID_SERVICE_FS)) { @@ -496,4 +499,10 @@ void PinetimeJFDevice::sendWeather(CurrentWeather *weather) if (w){ w->sendWeather(weather); } + + PineTimeSimpleWeatherService *sw = qobject_cast(service(PineTimeSimpleWeatherService::UUID_SERVICE_SIMPLE_WEATHER)); + + if (sw){ + sw->sendWeather(weather); + } } diff --git a/daemon/src/services/mibandservice.cpp b/daemon/src/services/mibandservice.cpp index d8ca7456..a39ce800 100644 --- a/daemon/src/services/mibandservice.cpp +++ b/daemon/src/services/mibandservice.cpp @@ -781,7 +781,7 @@ void MiBandService::sendWeather(const CurrentWeather *weather, bool supportsCond QBuffer buffer(&buf); buffer.open(QIODevice::WriteOnly); - char temp = weather->temperature() - 273; + char temp = weather->temperature() - 273.15; qint32 dt = qToLittleEndian(weather->dateTime()); qDebug() << dt << temp << condition; @@ -830,8 +830,8 @@ void MiBandService::sendWeather(const CurrentWeather *weather, bool supportsCond buffer.putChar(NR_DAYS); buffer.putChar(condition); buffer.putChar(condition); - buffer.putChar((char) (weather->maxTemperature() - 273)); - buffer.putChar((char) (weather->minTemperature() - 273)); + buffer.putChar((char) (weather->maxTemperature() - 273.15)); + buffer.putChar((char) (weather->minTemperature() - 273.15)); if (supportsConditionString) { buffer.write(weather->description().toLatin1()); buffer.putChar((char)0x00); @@ -845,8 +845,8 @@ void MiBandService::sendWeather(const CurrentWeather *weather, bool supportsCond buffer.putChar(condition); buffer.putChar(condition); - buffer.putChar((char) (fc.maxTemperature() - 273)); - buffer.putChar((char) (fc.minTemperature() - 273)); + buffer.putChar((char) (fc.maxTemperature() - 273.15)); + buffer.putChar((char) (fc.minTemperature() - 273.15)); if (supportsConditionString) { buffer.write(fc.description().toLatin1()); diff --git a/daemon/src/services/pinetimesimpleweatherservice.cpp b/daemon/src/services/pinetimesimpleweatherservice.cpp new file mode 100644 index 00000000..8613061b --- /dev/null +++ b/daemon/src/services/pinetimesimpleweatherservice.cpp @@ -0,0 +1,141 @@ +#include "pinetimesimpleweatherservice.h" +#include "typeconversion.h" +#include "codec.h" + +#include +#include +#include + +const char* PineTimeSimpleWeatherService::UUID_SERVICE_SIMPLE_WEATHER = "00050000-78fc-48fe-8e23-433b3a1942d0"; +const char* PineTimeSimpleWeatherService::UUID_CHARACTERISTIC_SIMPLE_WEATHER_DATA = "00050001-78fc-48fe-8e23-433b3a1942d0"; + +PineTimeSimpleWeatherService::PineTimeSimpleWeatherService(const QString &path, QObject *parent) : QBLEService(UUID_SERVICE_SIMPLE_WEATHER, path, parent) +{ + qDebug() << Q_FUNC_INFO; +} + + +void PineTimeSimpleWeatherService::sendWeather(CurrentWeather *weather) +{ + + qDebug() << "Current weather data" +#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) + << QDateTime::fromSecsSinceEpoch(weather->dateTime()) +#else + << QDateTime::fromTime_t(weather->dateTime()) +#endif + << weather->dateTime() + << weather->temperature() - 273.15 + << weather->minTemperature() - 273.15 + << weather->maxTemperature() - 273.15 + << weather->city()->name() + << weather->weatherIcon() + << QMetaEnum::fromType().valueToKey( + (int)iconToEnum(weather->weatherIcon()) + ) + << (int)iconToEnum(weather->weatherIcon()) +// << weather->clouds() +// << weather->humidity() +// << weather->windDeg() +// << weather->windSpeed() +// << weather->windGusts() + ; + + QByteArray cityNameBytes = weather->city()->name().toLocal8Bit().left(32); + if(cityNameBytes.size() < 32) { +#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) + cityNameBytes.append(32-cityNameBytes.size(), 0x00); +#else + for (int i = 0; i < (32 - cityNameBytes.size()); i++) { + cityNameBytes.append( '\0' ); + } +#endif + } + + QByteArray weatherBytes; + + weatherBytes += TypeConversion::fromInt8(0); // message type + weatherBytes += TypeConversion::fromInt8(0); // version information + weatherBytes += TypeConversion::fromInt64(weather->dateTime()); + weatherBytes += TypeConversion::fromInt16( round((weather->temperature() - 273.15) * 100) ); + weatherBytes += TypeConversion::fromInt16( round((weather->minTemperature() - 273.15) * 100) ); + weatherBytes += TypeConversion::fromInt16( round((weather->maxTemperature() - 273.15) * 100) ); + weatherBytes += cityNameBytes; + weatherBytes += TypeConversion::fromInt8( (int)iconToEnum(weather->weatherIcon()) ); + +// weatherBytes += TypeConversion::fromInt8( weather->clouds() ); +// weatherBytes += TypeConversion::fromInt8( weather->humidity() ); + +// weatherBytes += TypeConversion::fromInt16( (int)(100 * weather->windDeg())); +// weatherBytes += TypeConversion::fromInt16((int)(100 * weather->windSpeed())); +// weatherBytes += TypeConversion::fromInt16((int)(100 * weather->windGusts())); + + qDebug() << "Weather bytes" << weatherBytes.toHex(); + + writeValue(UUID_CHARACTERISTIC_SIMPLE_WEATHER_DATA, weatherBytes); + + + int fcDays = std::min(weather->forecastCount(), 5); + + QByteArray forecastBytes; + forecastBytes += TypeConversion::fromInt8(1); // message type + forecastBytes += TypeConversion::fromInt8(0); // version information + forecastBytes += TypeConversion::fromInt64(weather->dateTime()); + forecastBytes += TypeConversion::fromInt8(fcDays); + + + + for (int f = 0; (f < fcDays); f++) { + CurrentWeather::Forecast fc = weather->forecast(f); +// qDebug() << "Forecast:" << f << fc.dateTime()<< fc.weatherCode() << (fc.maxTemperature() - 273) << (fc.minTemperature() - 273) << fc.humidity() << fc.pressure() << fc.windMaxSpeed() << fc.clouds(); + + + qDebug() << "Forecast Day" << f +#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) + << QDateTime::fromSecsSinceEpoch(fc.dateTime()) +#else + << QDateTime::fromTime_t(fc.dateTime()) +#endif + << fc.dateTime() + << fc.minTemperature() - 273.15 + << fc.maxTemperature() - 273.15 + << fc.weatherIcon() + << QMetaEnum::fromType().valueToKey( + (int)iconToEnum(fc.weatherIcon()) + ) + << (int)iconToEnum(fc.weatherIcon()) + ; + + forecastBytes += TypeConversion::fromInt16( round((fc.minTemperature() - 273.15) * 100) ); + forecastBytes += TypeConversion::fromInt16( round((fc.maxTemperature() - 273.15) * 100) ); + forecastBytes += TypeConversion::fromInt8( (int)iconToEnum(fc.weatherIcon()) ); + + } + + qDebug() << "Forecast bytes" << forecastBytes.toHex(); + + writeValue(UUID_CHARACTERISTIC_SIMPLE_WEATHER_DATA, forecastBytes); + +} + +PineTimeSimpleWeatherService::WeatherIcons PineTimeSimpleWeatherService::iconToEnum(const QString& iconName) { + if (iconName == "01d") return WeatherIcons::ClearSky; + if (iconName == "01n") return WeatherIcons::ClearSky; + if (iconName == "02d") return WeatherIcons::FewClouds; + if (iconName == "02n") return WeatherIcons::FewClouds; + if (iconName == "03d") return WeatherIcons::ScatteredClouds; + if (iconName == "03n") return WeatherIcons::ScatteredClouds; + if (iconName == "04d") return WeatherIcons::BrokenClouds; + if (iconName == "04n") return WeatherIcons::BrokenClouds; + if (iconName == "09d") return WeatherIcons::ShowerRain; + if (iconName == "09n") return WeatherIcons::ShowerRain; + if (iconName == "10d") return WeatherIcons::Rain; + if (iconName == "10n") return WeatherIcons::Rain; + if (iconName == "11d") return WeatherIcons::Thunderstorm; + if (iconName == "11n") return WeatherIcons::Thunderstorm; + if (iconName == "13d") return WeatherIcons::Snow; + if (iconName == "13n") return WeatherIcons::Snow; + if (iconName == "50d") return WeatherIcons::Mist; + if (iconName == "50n") return WeatherIcons::Mist; + return WeatherIcons::Unknown; +} diff --git a/daemon/src/services/pinetimesimpleweatherservice.h b/daemon/src/services/pinetimesimpleweatherservice.h new file mode 100644 index 00000000..b5e77478 --- /dev/null +++ b/daemon/src/services/pinetimesimpleweatherservice.h @@ -0,0 +1,39 @@ +#ifndef PINETIMESIMPLEWEATHERSERVICE_H +#define PINETIMESIMPLEWEATHERSERVICE_H + +#include +#include "qble/qbleservice.h" +#include "devices/abstractdevice.h" + +class PineTimeSimpleWeatherService : public QBLEService +{ + Q_OBJECT +public: + static const char *UUID_SERVICE_SIMPLE_WEATHER; + static const char *UUID_CHARACTERISTIC_SIMPLE_WEATHER_DATA; + + explicit PineTimeSimpleWeatherService(const QString &path, QObject *parent); + + + void sendWeather(CurrentWeather *weather); + + enum class WeatherIcons { + ClearSky = 0, + FewClouds = 1, + ScatteredClouds = 2, + BrokenClouds = 3, + ShowerRain = 4, + Rain = 5, + Thunderstorm = 6, + Snow = 7, + Mist = 8, + Unknown = 255 // for any icon not listed above + }; + + Q_ENUM(WeatherIcons) + + WeatherIcons iconToEnum(const QString& iconName); + +}; + +#endif // #define PINETIMESIMPLEWEATHERSERVICE_H diff --git a/daemon/src/typeconversion.cpp b/daemon/src/typeconversion.cpp index 766eecbc..60a85801 100644 --- a/daemon/src/typeconversion.cpp +++ b/daemon/src/typeconversion.cpp @@ -25,6 +25,23 @@ QByteArray fromInt32(int val) return QByteArray(1, val & 0xff) + QByteArray(1, ((val >> 8) & 0xff)) + QByteArray(1, ((val >> 16) & 0xff)) + QByteArray(1, ((val >> 24) & 0xff)); } +QByteArray fromInt64(long long int val) +{ + QByteArray ret = QByteArray(1, val & 0xff) + + QByteArray(1, ((val >> 8) & 0xff)) + + QByteArray(1, ((val >> 16) & 0xff)) + + QByteArray(1, ((val >> 24) & 0xff)) + + QByteArray(1, ((val >> 32) & 0xff)) + + QByteArray(1, ((val >> 40) & 0xff)) + + QByteArray(1, ((val >> 48) & 0xff)) + + QByteArray(1, ((val >> 56) & 0xff)); + + qDebug() << "Converting int64 to char" << val << " " << ret.toHex(); + + return ret; +} + + QByteArray dateTimeToBytes(const QDateTime &dt, int format, bool adjustForTZ) { QByteArray ret; @@ -129,7 +146,6 @@ int toUint16(char val1, char val2) { return (val1 & 0xff) | ((val2 & 0xff) << 8); } - int toUint32(char val1, char val2, char val3, char val4) { return (val1 & 0xff) | ((val2 & 0xff) << 8) | ((val3 & 0xff) << 16) | ((val4 & 0xff) << 24); } diff --git a/daemon/src/typeconversion.h b/daemon/src/typeconversion.h index b16bff81..140e70ea 100644 --- a/daemon/src/typeconversion.h +++ b/daemon/src/typeconversion.h @@ -9,6 +9,7 @@ QByteArray fromInt8(int val); QByteArray fromInt16(int val); QByteArray fromInt24(int val); QByteArray fromInt32(int val); +QByteArray fromInt64(long long int val); QDateTime rawBytesToDateTime(const QByteArray &value, bool honorDeviceTimeOffset); QByteArray dateTimeToBytes(const QDateTime &dt, int format, bool adjustForTZ = true); int toUint16(char val1, char val2); diff --git a/lib/src/weather/currentweather.cpp b/lib/src/weather/currentweather.cpp index 13a3d17b..6b833f74 100644 --- a/lib/src/weather/currentweather.cpp +++ b/lib/src/weather/currentweather.cpp @@ -61,7 +61,7 @@ void CurrentWeather::setCity(City *city) } } -int CurrentWeather::temperature() const +qreal CurrentWeather::temperature() const { return m_temperature; } @@ -109,11 +109,21 @@ void CurrentWeather::handleCurrent(const QByteArray &reply) QJsonObject weather = object.value("weather").toArray().first().toObject(); m_weatherCode = weather.value("id").toVariant().toInt(); m_description = weather.value("description").toVariant().toString(); + m_weatherIcon = weather.value("icon").toVariant().toString(); + + QJsonObject wind = object.value("wind").toArray().first().toObject(); + m_windDeg = wind.value("wind_deg").toVariant().toDouble(); + m_windSpeed = wind.value("wind_speed").toVariant().toDouble(); + m_windGusts = wind.value("wind_gusts").toVariant().toDouble(); + + QJsonObject clouds = object.value("clouds").toArray().first().toObject(); + m_clouds = clouds.value("all").toVariant().toInt(); QJsonObject main = object.value("main").toObject(); - m_temperature = int(main.value("temp").toDouble()); - m_minTemperature = int(main.value("temp_min").toDouble()); - m_maxTemperature = int(main.value("temp_max").toDouble()); + m_temperature = main.value("temp").toDouble(); + m_minTemperature = main.value("temp_min").toDouble(); + m_maxTemperature = main.value("temp_max").toDouble(); + m_humidity = main.value("humidity").toDouble(); } void CurrentWeather::handleForecast(const QByteArray &reply) @@ -152,27 +162,29 @@ void CurrentWeather::handleForecast(const QByteArray &reply) QJsonObject weather = obj.value("weather").toArray().first().toObject(); + QString weatherIcon = weather.value("icon").toVariant().toString(); + int code = weather.value("id").toVariant().toInt(); QString desc = weather.value("description").toVariant().toString(); QJsonObject main = obj.value("main").toObject(); - int min_temp = int(main.value("temp_min").toDouble()); - int max_temp = int(main.value("temp_max").toDouble()); + int min_temp = main.value("temp_min").toDouble(); + int max_temp = main.value("temp_max").toDouble(); int wind_speed = 0; f.setWindMaxSpeed(0); f.setWindMinSpeed(255); if (obj.contains("rain")) { QJsonObject rain = obj.value("rain").toObject(); - total_rain += int(rain.value("3h").toDouble()); + total_rain += rain.value("3h").toDouble(); } if (obj.contains("snow")) { QJsonObject snow = obj.value("snow").toObject(); - total_snow += int(snow.value("3h").toDouble()); + total_snow += snow.value("3h").toDouble(); } if (obj.contains("wind")) { QJsonObject wind = obj.value("wind").toObject(); - wind_speed += int(wind.value("speed").toDouble()); + wind_speed += wind.value("speed").toDouble(); } qDebug() << "Forecast on " << dt << d << t << min_temp << max_temp << desc << code << "Hour:" << t.hour(); @@ -197,8 +209,9 @@ void CurrentWeather::handleForecast(const QByteArray &reply) f.setDateTime(dt); f.setDescription(desc); f.setWeatherCode(code); - f.setPressure(int(main.value("pressure").toDouble())); - f.setHumidity(int(main.value("humidity").toDouble())); + f.setWeatherIcon(weatherIcon); + f.setPressure(main.value("pressure").toDouble()); + f.setHumidity(main.value("humidity").toDouble()); } if (max_temp > f.maxTemperature()){ f.setMaxTemperature(max_temp); @@ -308,12 +321,42 @@ int CurrentWeather::weatherCode() const return m_weatherCode; } -int CurrentWeather::minTemperature() const +QString CurrentWeather::weatherIcon() const +{ + return m_weatherIcon; +} + +qreal CurrentWeather::windDeg() const +{ + return m_windDeg; +} + +qreal CurrentWeather::windSpeed() const +{ + return m_windSpeed; +} + +qreal CurrentWeather::windGusts() const +{ + return m_windGusts; +} + +int CurrentWeather::humidity() const +{ + return m_humidity; +} + +int CurrentWeather::clouds() const +{ + return m_clouds; +} + +qreal CurrentWeather::minTemperature() const { return m_minTemperature; } -int CurrentWeather::maxTemperature() const +qreal CurrentWeather::maxTemperature() const { return m_maxTemperature; } @@ -328,22 +371,33 @@ QString CurrentWeather::description() const return m_description; } -int CurrentWeather::Forecast::minTemperature() const +qreal CurrentWeather::Forecast::minTemperature() const { return m_minTemperature; } -void CurrentWeather::Forecast::setMinTemperature(int minTemperature) +void CurrentWeather::Forecast::setMinTemperature(qreal minTemperature) { m_minTemperature = minTemperature; } -int CurrentWeather::Forecast::maxTemperature() const +qreal CurrentWeather::Forecast::maxTemperature() const { return m_maxTemperature; } -void CurrentWeather::Forecast::setMaxTemperature(int maxTemperature) +void CurrentWeather::Forecast::setWeatherIcon(QString _weatherIcon) +{ + m_weatherIcon = _weatherIcon; +} + +QString CurrentWeather::Forecast::weatherIcon() const +{ + return m_weatherIcon; +} + + +void CurrentWeather::Forecast::setMaxTemperature(qreal maxTemperature) { m_maxTemperature = maxTemperature; } diff --git a/lib/src/weather/currentweather.h b/lib/src/weather/currentweather.h index 9bccf1b5..b8b33428 100644 --- a/lib/src/weather/currentweather.h +++ b/lib/src/weather/currentweather.h @@ -46,15 +46,18 @@ class CurrentWeather : public QObject class Forecast { public: - int minTemperature() const; - void setMinTemperature(int minTemperature); + qreal minTemperature() const; + void setMinTemperature(qreal minTemperature); - int maxTemperature() const; - void setMaxTemperature(int maxTemperature); + qreal maxTemperature() const; + void setMaxTemperature(qreal maxTemperature); int weatherCode() const; void setWeatherCode(int weatherCode); + QString weatherIcon() const; + void setWeatherIcon(QString weatherIcon); + void setDescription(const QString &description); QString description() const; @@ -86,9 +89,9 @@ class CurrentWeather : public QObject void setWindDirection(uint8_t newWindDirection); private: - int m_temperature = 0; - int m_minTemperature = 0; - int m_maxTemperature = 0; + qreal m_temperature = 0; + qreal m_minTemperature = 0; + qreal m_maxTemperature = 0; int m_weatherCode = 0; QString m_description; qlonglong m_dateTime = 0; @@ -100,6 +103,7 @@ class CurrentWeather : public QObject uint8_t m_snowMMDay = 0; uint8_t m_humidity = 0; uint8_t m_pressure = 0; + QString m_weatherIcon; }; @@ -109,12 +113,29 @@ class CurrentWeather : public QObject QString language() const; void setLanguage(const QString &language); - Q_PROPERTY(int temperature READ temperature NOTIFY ready) - - int temperature() const; - int minTemperature() const; - int maxTemperature() const; + Q_PROPERTY(qreal temperature READ temperature NOTIFY ready) + Q_PROPERTY(qreal minTemperature READ minTemperature NOTIFY ready) + Q_PROPERTY(qreal maxTemperature READ maxTemperature NOTIFY ready) + Q_PROPERTY(int weatherCode READ weatherCode NOTIFY ready) + Q_PROPERTY(QString weatherIcon READ weatherIcon NOTIFY ready) + Q_PROPERTY(qreal windDeg READ windDeg NOTIFY ready) + Q_PROPERTY(qreal windSpeed READ windSpeed NOTIFY ready) + Q_PROPERTY(qreal windGusts READ windGusts NOTIFY ready) + Q_PROPERTY(int humidity READ humidity NOTIFY ready) + Q_PROPERTY(int clouds READ clouds NOTIFY ready) + + + qreal temperature() const; + qreal minTemperature() const; + qreal maxTemperature() const; int weatherCode() const; + QString weatherIcon() const; + qreal windDeg() const; + qreal windSpeed() const; + qreal windGusts() const; + int humidity() const; + int clouds() const; + QString description() const; qlonglong dateTime() const; @@ -141,10 +162,18 @@ class CurrentWeather : public QObject City *m_city = nullptr; QString m_language; - int m_temperature = 0; - int m_minTemperature = 0; - int m_maxTemperature = 0; + qreal m_temperature = 0; + qreal m_minTemperature = 0; + qreal m_maxTemperature = 0; int m_weatherCode = 0; + QString m_weatherIcon; + + qreal m_windDeg = 0; + qreal m_windSpeed = 0; + qreal m_windGusts = 0; + int m_humidity = 0; + int m_clouds = 0; + QString m_description; qlonglong m_dateTime = 0; diff --git a/ui/qml/components/platform.uuitk/StylerPL.qml b/ui/qml/components/platform.uuitk/StylerPL.qml index e9afcdb0..f4730fa8 100644 --- a/ui/qml/components/platform.uuitk/StylerPL.qml +++ b/ui/qml/components/platform.uuitk/StylerPL.qml @@ -115,7 +115,7 @@ QtObject { property string iconDiagnostic: "image://theme/info" // "Debug Info" property string iconFavoriteSelected: "image://theme/bookmark" // "Donate" - + property string customIconPrefix: "../../pics/custom-icons/" // item sizes property real themeItemSizeLarge: themeFontSizeLarge * 3 diff --git a/ui/qml/pages/AddCityPage.qml b/ui/qml/pages/AddCityPage.qml index 936e0855..9bac38f6 100644 --- a/ui/qml/pages/AddCityPage.qml +++ b/ui/qml/pages/AddCityPage.qml @@ -16,6 +16,30 @@ PagePL { id: weather } + function owmIconToLocal(omw) { + const weatherIcons = { + '01d': 'weather-clear.png', + '01n': 'weather-clear-night.png', + '02d': 'weather-few-clouds.png', + '02n': 'weather-few-clouds-night.png', + '03d': 'weather-clouds.png', + '03n': 'weather-clouds-night.png', + '04d': 'weather-many-clouds.png', + '04n': 'weather-many-clouds.png', // Assuming night uses the same icon for "many clouds" + '09d': 'weather-showers.png', + '09n': 'weather-showers-night.png', + '10d': 'weather-showers-scattered-day.png', + '10n': 'weather-showers-scattered-night.png', + '11d': 'weather-storm-day.png', + '11n': 'weather-storm-night.png', + '13d': 'weather-snow.png', + '13n': 'weather-snow-scattered-night.png', // Assuming scattered snow at night for 13n + '50d': 'weather-mist.png', + '50n': 'weather-mist.png' // Assuming night uses the same icon for "mist" + }; + return "../pics/" + weatherIcons[omw]; + } + onCurrentCityChanged: { if ((cityManager == null) || (cityManager.cities.length <= 0)) { return @@ -34,11 +58,26 @@ PagePL { id: citymodel } - LabelPL { - text: page.currentCity + ( - (weather.temperature !== 0) ? " " + (weather.temperature-273) + "˚C" : "" - ) - visible: page.currentCity !== "" + + Row { + width: parent.width - (2 * anchors.margins) + LabelPL { + text: page.currentCity + width: parent.width * 0.75 + } + + LabelPL { + id: temperatureLabel + text: (weather.weatherIcon !== "") ? (Math.round(weather.temperature-273.15) + "˚C") : "" + width: parent.width * 0.15 + + } + + IconPL { + source: (weather.weatherIcon !== "") ? owmIconToLocal(weather.weatherIcon) : "" + height: temperatureLabel.height + } + } SearchFieldPL {