diff options
| -rw-r--r-- | protocols/Weather/src/proto.h | 15 | ||||
| -rw-r--r-- | protocols/Weather/src/weather_update.cpp | 12 |
2 files changed, 24 insertions, 3 deletions
diff --git a/protocols/Weather/src/proto.h b/protocols/Weather/src/proto.h index 3e990931d1..b44c193110 100644 --- a/protocols/Weather/src/proto.h +++ b/protocols/Weather/src/proto.h @@ -12,6 +12,21 @@ struct WIDATAITEM CMStringW Value; }; +struct WIDATAITEMLIST : public OBJLIST<WIDATAITEM> +{ + WIDATAITEMLIST() : + OBJLIST<WIDATAITEM>(20) + {} + + WIDATAITEM* Find(const wchar_t *pwszName) + { + for (auto &it : *this) + if (!mir_wstrcmp(it->Name, pwszName)) + return it; + return 0; + } +}; + struct WEATHERINFO { MCONTACT hContact; diff --git a/protocols/Weather/src/weather_update.cpp b/protocols/Weather/src/weather_update.cpp index 7e44869876..806d41002c 100644 --- a/protocols/Weather/src/weather_update.cpp +++ b/protocols/Weather/src/weather_update.cpp @@ -404,7 +404,7 @@ int CWeatherProto::GetWeatherData(MCONTACT hContact) auto &curr = root["currentConditions"]; g_elevation = root["elevation"].as_float() / 7.877; - OBJLIST<WIDATAITEM> arValues(20); + WIDATAITEMLIST arValues; getData(arValues, curr); auto szIcon = curr["icon"].as_string(); @@ -430,7 +430,6 @@ int CWeatherProto::GetWeatherData(MCONTACT hContact) cond = CLOUDY; // writing forecast - int iFore = 0; db_set_ws(hContact, WEATHERCONDITION, "Update", curr["datetime"].as_mstring()); for (auto &it : arValues) { @@ -439,8 +438,9 @@ int CWeatherProto::GetWeatherData(MCONTACT hContact) db_set_ws(hContact, WEATHERCONDITION, _T2A(it->Name), it->Value); } + int iFore = 0; for (auto &fore : root["days"]) { - OBJLIST<WIDATAITEM> arDaily(20); + WIDATAITEMLIST arDaily; getData(arDaily, fore); CMStringW result; @@ -449,6 +449,12 @@ int CWeatherProto::GetWeatherData(MCONTACT hContact) if (it->Value.IsEmpty()) continue; + // insert missing values from day 0 into current + if (iFore == 0) + if (auto *pOld = arValues.Find(it->Name)) + if (pOld->Value.IsEmpty() || pOld->Value == NODATA) + db_set_ws(hContact, WEATHERCONDITION, _T2A(it->Name), it->Value); + if (!result.IsEmpty()) result += L"; "; result.AppendFormat(L"%s: %s", TranslateW(it->Name), it->Value.c_str()); |
