diff options
Diffstat (limited to 'protocols/Weather/src')
| -rw-r--r-- | protocols/Weather/src/proto.h | 2 | ||||
| -rw-r--r-- | protocols/Weather/src/resource.h | 1 | ||||
| -rw-r--r-- | protocols/Weather/src/stdafx.h | 2 | ||||
| -rw-r--r-- | protocols/Weather/src/weather_addstn.cpp | 2 | ||||
| -rw-r--r-- | protocols/Weather/src/weather_contacts.cpp | 18 | ||||
| -rw-r--r-- | protocols/Weather/src/weather_conv.cpp | 59 | ||||
| -rw-r--r-- | protocols/Weather/src/weather_data.cpp | 16 | ||||
| -rw-r--r-- | protocols/Weather/src/weather_mwin.cpp | 4 | ||||
| -rw-r--r-- | protocols/Weather/src/weather_opt.cpp | 98 | ||||
| -rw-r--r-- | protocols/Weather/src/weather_popup.cpp | 4 | ||||
| -rw-r--r-- | protocols/Weather/src/weather_proto.cpp | 4 | ||||
| -rw-r--r-- | protocols/Weather/src/weather_update.cpp | 60 | ||||
| -rw-r--r-- | protocols/Weather/src/weather_userinfo.cpp | 20 |
13 files changed, 165 insertions, 125 deletions
diff --git a/protocols/Weather/src/proto.h b/protocols/Weather/src/proto.h index e83fee46eb..e1115b65e3 100644 --- a/protocols/Weather/src/proto.h +++ b/protocols/Weather/src/proto.h @@ -151,7 +151,6 @@ class CWeatherProto : public PROTO<CWeatherProto> // data void ConvertDataValue(WIDATAITEM *UpdateData); void EraseAllInfo(void); - void GetStationID(MCONTACT hContact, wchar_t *id, int idlen); WEATHERINFO LoadWeatherInfo(MCONTACT hContact); MHttpResponse* RunQuery(const wchar_t *id, int days); @@ -182,6 +181,7 @@ class CWeatherProto : public PROTO<CWeatherProto> int __cdecl OptInit(WPARAM, LPARAM); CMStringW GetTextValue(int c); + void GetVarsDescr(CMStringW &str); // popups int WPShowMessage(const wchar_t *lpzText, int kind); diff --git a/protocols/Weather/src/resource.h b/protocols/Weather/src/resource.h index e53877d0ee..809c94857b 100644 --- a/protocols/Weather/src/resource.h +++ b/protocols/Weather/src/resource.h @@ -109,6 +109,7 @@ #define IDC_INFO10 2091 #define IDC_INFO12 2092 #define IDC_INFO13 2093 +#define IDC_MORE 2094 #define IDC_MOREDETAIL 2095 #define IDC_DATALIST 2096 #define IDC_MUPDATE 2097 diff --git a/protocols/Weather/src/stdafx.h b/protocols/Weather/src/stdafx.h index eec03bd13e..cf1f3240a3 100644 --- a/protocols/Weather/src/stdafx.h +++ b/protocols/Weather/src/stdafx.h @@ -146,7 +146,7 @@ void TrimString(wchar_t *str); void ConvertBackslashes(char *str);
char *GetSearchStr(char *dis);
-wchar_t *GetDisplay(WEATHERINFO *w, const wchar_t *dis, wchar_t* str);
+CMStringW GetDisplay(WEATHERINFO *w, const wchar_t *dis);
wchar_t *GetError(int code);
diff --git a/protocols/Weather/src/weather_addstn.cpp b/protocols/Weather/src/weather_addstn.cpp index 1bdfb9b49d..026b9f8c67 100644 --- a/protocols/Weather/src/weather_addstn.cpp +++ b/protocols/Weather/src/weather_addstn.cpp @@ -88,7 +88,7 @@ MCONTACT CWeatherProto::AddToList(int, PROTOSEARCHRESULT *psr) // if no default station is found, set the new contact as default station if (opt.Default[0] == 0) { - GetStationID(hContact, opt.Default, _countof(opt.Default)); + wcsncpy_s(opt.Default, getMStringW(hContact, "ID"), _countof(opt.Default)); opt.DefStn = hContact; ptrW wszNick(getWStringA(hContact, "Nick")); diff --git a/protocols/Weather/src/weather_contacts.cpp b/protocols/Weather/src/weather_contacts.cpp index 2661c1b20e..2f5a08f4ef 100644 --- a/protocols/Weather/src/weather_contacts.cpp +++ b/protocols/Weather/src/weather_contacts.cpp @@ -53,13 +53,12 @@ INT_PTR CWeatherProto::ViewLog(WPARAM wParam, LPARAM lParam) // read complete forecast // wParam = current contact -INT_PTR CWeatherProto::LoadForecast(WPARAM wParam, LPARAM) +INT_PTR CWeatherProto::LoadForecast(WPARAM hContact, LPARAM) { - wchar_t id[256]; - GetStationID(wParam, id, _countof(id)); - if (id[0] != 0) { + CMStringW wszID(getMStringW(hContact, "ID")); + if (!wszID.IsEmpty()) { // set the url and open the webpage - CMStringA szUrl("https://www.visualcrossing.com/weather-forecast/" + mir_urlEncode(T2Utf(id)) + "/metric"); + CMStringA szUrl("https://www.visualcrossing.com/weather-forecast/" + mir_urlEncode(T2Utf(wszID)) + "/metric"); Utils_OpenUrl(szUrl); } return 0; @@ -69,13 +68,12 @@ INT_PTR CWeatherProto::LoadForecast(WPARAM wParam, LPARAM) // load weather map // wParam = current contact -INT_PTR CWeatherProto::WeatherMap(WPARAM wParam, LPARAM) +INT_PTR CWeatherProto::WeatherMap(WPARAM hContact, LPARAM) { - wchar_t id[256]; - GetStationID(wParam, id, _countof(id)); - if (id[0] != 0) { + CMStringW wszID(getMStringW(hContact, "ID")); + if (!wszID.IsEmpty()) { // set the url and open the webpage - CMStringA szUrl("https://www.visualcrossing.com/weather-history/" + mir_urlEncode(T2Utf(id)) + "/metric"); + CMStringA szUrl("https://www.visualcrossing.com/weather-history/" + mir_urlEncode(T2Utf(wszID)) + "/metric"); Utils_OpenUrl(szUrl); } diff --git a/protocols/Weather/src/weather_conv.cpp b/protocols/Weather/src/weather_conv.cpp index d9f35264b0..4d2c79f0ce 100644 --- a/protocols/Weather/src/weather_conv.cpp +++ b/protocols/Weather/src/weather_conv.cpp @@ -399,7 +399,7 @@ char* GetSearchStr(char *dis) // dis = the string to parse // return value = the parsed string -wchar_t* GetDisplay(WEATHERINFO *w, const wchar_t *dis, wchar_t *str) +CMStringW GetDisplay(WEATHERINFO *w, const wchar_t *dis) { wchar_t lpzDate[32], chr; char name[256], temp[2]; @@ -407,7 +407,7 @@ wchar_t* GetDisplay(WEATHERINFO *w, const wchar_t *dis, wchar_t *str) size_t i; // Clear the string - str[0] = 0; + CMStringW str; // looking character by character for (i = 0; i < mir_wstrlen(dis); i++) { @@ -416,10 +416,10 @@ wchar_t* GetDisplay(WEATHERINFO *w, const wchar_t *dis, wchar_t *str) i++; chr = dis[i]; switch (chr) { - case '%': mir_wstrcat(str, L"%"); break; - case 't': mir_wstrcat(str, L"\t"); break; - case 'n': mir_wstrcat(str, L"\r\n"); break; - case '\\': mir_wstrcat(str, L"\\"); break; + case '%': str.Append(L"%"); break; + case 't': str.Append(L"\t"); break; + case 'n': str.Append(L"\r\n"); break; + case '\\': str.Append(L"\\"); break; } } @@ -430,29 +430,31 @@ wchar_t* GetDisplay(WEATHERINFO *w, const wchar_t *dis, wchar_t *str) // turn capitalized characters to small case if (chr < 'a' && chr != '[' && chr != '%') chr = (char)((int)chr + 32); switch (chr) { - case 'c': mir_wstrcat(str, w->cond); break; + case 'c': str.Append(w->cond); break; case 'd': // get the current date GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, nullptr, nullptr, lpzDate, _countof(lpzDate)); - mir_wstrcat(str, lpzDate); break; - case 'e': mir_wstrcat(str, w->dewpoint); break; - case 'f': mir_wstrcat(str, w->feel); break; - case 'h': mir_wstrcat(str, w->high); break; - case 'i': mir_wstrcat(str, w->winddir); break; - case 'l': mir_wstrcat(str, w->low); break; - case 'm': mir_wstrcat(str, w->humid); break; - case 'n': mir_wstrcat(str, w->city); break; - case 'p': mir_wstrcat(str, w->pressure); break; - case 'r': mir_wstrcat(str, w->sunrise); break; - case 's': mir_wstrcat(str, w->id); break; - case 't': mir_wstrcat(str, w->temp); break; + str.Append(lpzDate); break; + case 'e': str.Append(w->dewpoint); break; + case 'f': str.Append(w->feel); break; + case 'h': str.Append(w->high); break; + case 'i': str.Append(w->winddir); break; + case 'l': str.Append(w->low); break; + case 'm': str.Append(w->humid); break; + case 'n': str.Append(w->city); break; + case 'p': str.Append(w->pressure); break; + case 'r': str.Append(w->sunrise); break; + case 's': str.Append(w->id); break; + case 't': str.Append(w->temp); break; case 'u': - if (mir_wstrcmp(w->update, NODATA)) mir_wstrcat(str, w->update); - else mir_wstrcat(str, TranslateT("<unknown time>")); + if (mir_wstrcmp(w->update, NODATA)) + str.Append(w->update); + else + str.Append(TranslateT("<unknown time>")); break; - case 'v': mir_wstrcat(str, w->vis); break; - case 'w': mir_wstrcat(str, w->wind); break; - case 'y': mir_wstrcat(str, w->sunset); break; - case '%': mir_wstrcat(str, L"%"); break; + case 'v': str.Append(w->vis); break; + case 'w': str.Append(w->wind); break; + case 'y': str.Append(w->sunset); break; + case '%': str.Append(L"%"); break; case '[': // custom variables i++; name[0] = 0; @@ -464,17 +466,14 @@ wchar_t* GetDisplay(WEATHERINFO *w, const wchar_t *dis, wchar_t *str) // access the database to get its value if (!db_get_ws(w->hContact, WEATHERCONDITION, name, &dbv)) { if (dbv.pwszVal != TranslateW(NODATA) && dbv.pwszVal != TranslateT("<Error>")) - mir_wstrcat(str, dbv.pwszVal); + str.Append(dbv.pwszVal); db_free(&dbv); } break; } } // if the character is not a variable, write the original character to the new string - else { - mir_snwprintf(lpzDate, L"%c", dis[i]); - mir_wstrcat(str, lpzDate); - } + else str.AppendChar(dis[i]); } return str; diff --git a/protocols/Weather/src/weather_data.cpp b/protocols/Weather/src/weather_data.cpp index a02ae0dc1f..76e50ca139 100644 --- a/protocols/Weather/src/weather_data.cpp +++ b/protocols/Weather/src/weather_data.cpp @@ -26,18 +26,6 @@ saving individual weather data for a weather contact. #include "stdafx.h" ///////////////////////////////////////////////////////////////////////////////////////// -// get station ID from DB -// hContact = the current contact handle -// return value = the string for station ID - -void CWeatherProto::GetStationID(MCONTACT hContact, wchar_t *id, int idlen) -{ - // accessing the database - if (db_get_wstatic(hContact, m_szModuleName, "ID", id, idlen)) - id[0] = 0; -} - -///////////////////////////////////////////////////////////////////////////////////////// // initialize weather info by loading values from database // hContact = current contact handle // return value = the current weather information in WEATHERINFO struct @@ -49,7 +37,7 @@ WEATHERINFO CWeatherProto::LoadWeatherInfo(MCONTACT hContact) // if the string is not found in database, a value of "N/A" is stored in the field WEATHERINFO winfo; winfo.hContact = hContact; - GetStationID(hContact, winfo.id, _countof(winfo.id)); + wcsncpy_s(winfo.id, getMStringW(hContact, "ID"), _countof(winfo.id)); if (db_get_wstatic(hContact, m_szModuleName, "Nick", winfo.city, _countof(winfo.city))) wcsncpy(winfo.city, NODATA, _countof(winfo.city) - 1); @@ -121,7 +109,7 @@ void CWeatherProto::EraseAllInfo() // if no default station find, assign a new one if (opt.Default[0] == 0) { - GetStationID(hContact, opt.Default, _countof(opt.Default)); + wcsncpy_s(opt.Default, getMStringW(hContact, "ID"), _countof(opt.Default)); opt.DefStn = hContact; if (!getWString(hContact, "Nick", &dbv)) { diff --git a/protocols/Weather/src/weather_mwin.cpp b/protocols/Weather/src/weather_mwin.cpp index 57b775c81b..058c6e56ad 100644 --- a/protocols/Weather/src/weather_mwin.cpp +++ b/protocols/Weather/src/weather_mwin.cpp @@ -340,7 +340,7 @@ void CWeatherProto::InitMwin(void) g_plugin.addFont(&fontid); for (auto &hContact : AccContacts()) - if (g_plugin.getDword(hContact, "mwin")) + if (getDword(hContact, "mwin")) AddFrameWindow(hContact); hFontHook = HookEvent(ME_FONT_RELOAD, RedrawFrame); @@ -349,7 +349,7 @@ void CWeatherProto::InitMwin(void) void CWeatherProto::DestroyMwin(void) { for (auto &hContact : AccContacts()) { - uint32_t frameId = g_plugin.getDword(hContact, "mwin"); + uint32_t frameId = getDword(hContact, "mwin"); if (frameId) CallService(MS_CLIST_FRAMES_REMOVEFRAME, frameId, 0); } diff --git a/protocols/Weather/src/weather_opt.cpp b/protocols/Weather/src/weather_opt.cpp index a0b42e21be..765309e414 100644 --- a/protocols/Weather/src/weather_opt.cpp +++ b/protocols/Weather/src/weather_opt.cpp @@ -295,8 +295,6 @@ public: ///////////////////////////////////////////////////////////////////////////////////////// // text option dialog -#define VAR_LIST_OPT TranslateT("%c\tcurrent condition\n%d\tcurrent date\n%e\tdewpoint\n%f\tfeel-like temp\n%h\ttoday's high\n%i\twind direction\n%l\ttoday's low\n%m\thumidity\n%n\tstation name\n%p\tpressure\n%r\tsunrise time\n%s\tstation ID\n%t\ttemperature\n%u\tupdate time\n%v\tvisibility\n%w\twind speed\n%y\tsun set\n----------\n\\n\tnew line") - struct { wchar_t c; @@ -315,13 +313,40 @@ static controls[] = { 'S', IDC_BTITLE2, "StatusText" }, }; +struct +{ + wchar_t symbol; + const wchar_t *pwszText; +} +static variables[] = +{ + { 'c', LPGENW("Current condition") }, + { 'd', LPGENW("Current date") }, + { 'e', LPGENW("Dewpoint") }, + { 'f', LPGENW("Feel-like temp") }, + { 'h', LPGENW("Today's high") }, + { 'i', LPGENW("Wind direction") }, + { 'l', LPGENW("Today's low") }, + { 'm', LPGENW("Humidity") }, + { 'n', LPGENW("Station name") }, + { 'p', LPGENW("Pressure") }, + { 'r', LPGENW("Sunrise") }, + { 's', LPGENW("Station ID") }, + { 't', LPGENW("Temperature") }, + { 'u', LPGENW("Update time") }, + { 'v', LPGENW("Visibility") }, + { 'w', LPGENW("Wind speed") }, + { 'y', LPGENW("Sunset") }, +}; + class COptionsTextDlg : public CWeatherDlgBase { - CCtrlMButton btnReset, tm1, tm2, tm3, tm4, tm5, tm6, tm7, tm8; + CCtrlMButton btnMore, btnReset, tm1, tm2, tm3, tm4, tm5, tm6, tm7, tm8; public: COptionsTextDlg(CWeatherProto *ppro) : CWeatherDlgBase(ppro, IDD_TEXTOPT), + btnMore(this, IDC_MORE), btnReset(this, IDC_RESET), tm1(this, IDC_TM1), tm2(this, IDC_TM2), @@ -332,6 +357,7 @@ public: tm7(this, IDC_TM7), tm8(this, IDC_TM8) { + btnMore.OnClick = Callback(this, &COptionsTextDlg::onClick_More); btnReset.OnClick = Callback(this, &COptionsTextDlg::onClick_Reset); tm1.OnClick = tm2.OnClick = tm3.OnClick = tm4.OnClick = tm5.OnClick = tm6.OnClick = tm7.OnClick = tm8.OnClick = @@ -346,7 +372,12 @@ public: SetWindowPos(m_hwnd, HWND_TOPMOST, rc.left, rc.top, 0, 0, SWP_NOSIZE); // generate the display text for variable list - SetDlgItemTextW(m_hwnd, IDC_VARLIST, VAR_LIST_OPT); + CMStringW str; + for (auto &it : variables) + str.AppendFormat(L"%%%c\t%s\r\n", it.symbol, TranslateW(it.pwszText)); + str.Append(L"----------\r\n"); + str.AppendFormat(L"\\n\t%s\r\n", TranslateT("new line")); + SetDlgItemTextW(m_hwnd, IDC_VARLIST, str); for (auto &it : controls) SetDlgItemTextW(m_hwnd, it.id, m_proto->GetTextValue(it.c)); @@ -360,6 +391,7 @@ public: tm6.MakeFlat(); tm7.MakeFlat(); tm8.MakeFlat(); + btnMore.MakeFlat(); btnReset.MakeFlat(); return true; } @@ -367,8 +399,8 @@ public: bool OnApply() override { // save the option - wchar_t textstr[MAX_TEXT_SIZE]; for (auto &it : controls) { + wchar_t textstr[MAX_TEXT_SIZE]; GetDlgItemText(m_hwnd, it.id, textstr, _countof(textstr)); if (!mir_wstrcmpi(textstr, GetDefaultText(it.c))) m_proto->delSetting(it.setting); @@ -381,45 +413,55 @@ public: return true; } + void onClick_More(CCtrlButton *) + { + // heading + CMStringW str(TranslateT("Here is a list of custom variables that are currently available")); + str += L"\n\n"; + m_proto->GetVarsDescr(str); + + // display the list in a message box + MessageBox(nullptr, str, TranslateT("More Variables"), MB_OK | MB_ICONINFORMATION | MB_TOPMOST); + } + void onClick_TM(CCtrlButton *pButton) { // display the menu - RECT pos; - GetWindowRect(pButton->GetHwnd(), &pos); HMENU hMenu = LoadMenu(g_plugin.getInst(), MAKEINTRESOURCE(IDR_TMMENU)); HMENU hMenu1 = GetSubMenu(hMenu, 0); TranslateMenu(hMenu1); - { - auto &var = controls[pButton->GetCtrlId() - IDC_TM1]; - - switch (TrackPopupMenu(hMenu1, TPM_LEFTBUTTON | TPM_RETURNCMD, pos.left, pos.bottom, 0, m_hwnd, nullptr)) { - case ID_MPREVIEW: - { - // show the preview in a message box, using the weather data from the default station - WEATHERINFO winfo = m_proto->LoadWeatherInfo(m_proto->opt.DefStn); - wchar_t buf[MAX_TEXT_SIZE], str[4096]; - GetDlgItemTextW(m_hwnd, var.id, buf, _countof(buf)); - GetDisplay(&winfo, buf, str); - MessageBox(nullptr, str, TranslateT("Weather Protocol Text Preview"), MB_OK | MB_TOPMOST); - } - break; - - case ID_MRESET: - SetDlgItemTextW(m_hwnd, var.id, GetDefaultText(var.c)); - break; + + auto &var = controls[pButton->GetCtrlId() - IDC_TM1]; + + RECT pos; + GetWindowRect(pButton->GetHwnd(), &pos); + switch (TrackPopupMenu(hMenu1, TPM_LEFTBUTTON | TPM_RETURNCMD, pos.left, pos.bottom, 0, m_hwnd, nullptr)) { + case ID_MPREVIEW: + { + // show the preview in a message box, using the weather data from the default station + WEATHERINFO winfo = m_proto->LoadWeatherInfo(m_proto->opt.DefStn); + wchar_t buf[MAX_TEXT_SIZE]; + GetDlgItemTextW(m_hwnd, var.id, buf, _countof(buf)); + MessageBox(nullptr, GetDisplay(&winfo, buf), TranslateT("Weather Protocol Text Preview"), MB_OK | MB_TOPMOST); } - DestroyMenu(hMenu); + break; + + case ID_MRESET: + SetDlgItemTextW(m_hwnd, var.id, GetDefaultText(var.c)); + break; } + DestroyMenu(hMenu); } void onClick_Reset(CCtrlButton *) { // left click action selection menu - RECT pos; - GetWindowRect(btnReset.GetHwnd(), &pos); HMENU hMenu = LoadMenu(g_plugin.getInst(), MAKEINTRESOURCE(IDR_TMENU)); HMENU hMenu1 = GetSubMenu(hMenu, 0); TranslateMenu(hMenu1); + + RECT pos; + GetWindowRect(btnReset.GetHwnd(), &pos); switch (TrackPopupMenu(hMenu1, TPM_LEFTBUTTON | TPM_RETURNCMD, pos.left, pos.bottom, 0, m_hwnd, nullptr)) { case ID_T1: // reset to the strings in memory, discard all changes diff --git a/protocols/Weather/src/weather_popup.cpp b/protocols/Weather/src/weather_popup.cpp index 91dcf51cb9..b9f938e41d 100644 --- a/protocols/Weather/src/weather_popup.cpp +++ b/protocols/Weather/src/weather_popup.cpp @@ -120,8 +120,8 @@ int CWeatherProto::WeatherPopup(MCONTACT hContact, bool bAlways) POPUPDATAW ppd; ppd.lchContact = hContact; ppd.PluginData = ppd.lchIcon = GetStatusIcon(winfo.hContact); - GetDisplay(&winfo, GetTextValue('P'), ppd.lpwzContactName); - GetDisplay(&winfo, GetTextValue('p'), ppd.lpwzText); + wcsncpy_s(ppd.lpwzContactName, GetDisplay(&winfo, GetTextValue('P')), _TRUNCATE); + wcsncpy_s(ppd.lpwzText, GetDisplay(&winfo, GetTextValue('p')), _TRUNCATE); ppd.PluginWindowProc = PopupDlgProc; ppd.colorBack = (opt.UseWinColors) ? GetSysColor(COLOR_BTNFACE) : opt.BGColour; ppd.colorText = (opt.UseWinColors) ? GetSysColor(COLOR_WINDOWTEXT) : opt.TextColour; diff --git a/protocols/Weather/src/weather_proto.cpp b/protocols/Weather/src/weather_proto.cpp index 6df768e7ac..3c5f8f1057 100644 --- a/protocols/Weather/src/weather_proto.cpp +++ b/protocols/Weather/src/weather_proto.cpp @@ -32,8 +32,6 @@ CWeatherProto::CWeatherProto(const char *protoName, const wchar_t *userName) : HookProtoEvent(ME_CLIST_DOUBLECLICKED, &CWeatherProto::BriefInfoEvt); HookProtoEvent(ME_CLIST_PREBUILDCONTACTMENU, &CWeatherProto::BuildContactMenu); - InitMwin(); - // load options and set defaults LoadOptions(); @@ -63,6 +61,8 @@ CWeatherProto::~CWeatherProto() void CWeatherProto::OnModulesLoaded() { + InitMwin(); + // timer for the first update m_impl.m_start.Start(5000); // first update is 5 sec after load diff --git a/protocols/Weather/src/weather_update.cpp b/protocols/Weather/src/weather_update.cpp index 15713e110e..82437dbb72 100644 --- a/protocols/Weather/src/weather_update.cpp +++ b/protocols/Weather/src/weather_update.cpp @@ -32,7 +32,6 @@ menu items). int CWeatherProto::UpdateWeather(MCONTACT hContact) { - wchar_t str2[MAX_TEXT_SIZE]; DBVARIANT dbv; BOOL Ch = FALSE; @@ -128,22 +127,18 @@ int CWeatherProto::UpdateWeather(MCONTACT hContact) setWord(hContact, "Status", iStatus); AvatarDownloaded(hContact); - GetDisplay(&winfo, GetTextValue('C'), str2); - db_set_ws(hContact, "CList", "MyHandle", str2); + db_set_ws(hContact, "CList", "MyHandle", GetDisplay(&winfo, GetTextValue('C'))); - GetDisplay(&winfo, GetTextValue('S'), str2); - if (str2[0]) + CMStringW str2(GetDisplay(&winfo, GetTextValue('S'))); + if (!str2.IsEmpty()) db_set_ws(hContact, "CList", "StatusMsg", str2); else db_unset(hContact, "CList", "StatusMsg"); - - ProtoBroadcastAck(hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, nullptr, (LPARAM)(str2[0] ? str2 : nullptr)); + ProtoBroadcastAck(hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, nullptr, (LPARAM)(str2.IsEmpty() ? nullptr : str2.c_str())); // save descriptions in MyNotes - GetDisplay(&winfo, GetTextValue('N'), str2); - db_set_ws(hContact, "UserInfo", "MyNotes", str2); - GetDisplay(&winfo, GetTextValue('X'), str2); - db_set_ws(hContact, WEATHERCONDITION, "WeatherInfo", str2); + db_set_ws(hContact, "UserInfo", "MyNotes", GetDisplay(&winfo, GetTextValue('N'))); + db_set_ws(hContact, WEATHERCONDITION, "WeatherInfo", GetDisplay(&winfo, GetTextValue('X'))); // set the update tag setByte(hContact, "IsUpdated", TRUE); @@ -174,8 +169,7 @@ int CWeatherProto::UpdateWeather(MCONTACT hContact) db_free(&dbv); if (file != nullptr) { // write data to the file and close - GetDisplay(&winfo, GetTextValue('E'), str2); - fputws(str2, file); + fputws(GetDisplay(&winfo, GetTextValue('E')), file); fclose(file); } } @@ -183,9 +177,7 @@ int CWeatherProto::UpdateWeather(MCONTACT hContact) if (getByte(hContact, "History")) { // internal log using history - GetDisplay(&winfo, GetTextValue('H'), str2); - - T2Utf szMessage(str2); + T2Utf szMessage(GetDisplay(&winfo, GetTextValue('H'))); DBEVENTINFO dbei = {}; dbei.szModule = m_szModuleName; @@ -381,6 +373,7 @@ static double g_elevation = 0; static void getData(OBJLIST<WIDATAITEM> &arValues, const JSONNode &node) { + arValues.insert(new WIDATAITEM(LPGENW("Date"), L"", parseConditions(node["datetime"].as_mstring()))); arValues.insert(new WIDATAITEM(LPGENW("Condition"), L"", parseConditions(node["conditions"].as_mstring()))); arValues.insert(new WIDATAITEM(LPGENW("Temperature"), L"C", node["temp"].as_mstring())); arValues.insert(new WIDATAITEM(LPGENW("High"), L"C", node["tempmax"].as_mstring())); @@ -403,15 +396,14 @@ static void getData(OBJLIST<WIDATAITEM> &arValues, const JSONNode &node) int CWeatherProto::GetWeatherData(MCONTACT hContact) { // get each part of the id's - wchar_t id[256]; - GetStationID(hContact, id, _countof(id)); - if (id[0] == 0) + CMStringW wszID(getMStringW(hContact, "ID")); + if (wszID.IsEmpty()) return INVALID_ID; uint16_t cond = NA; // download the html file from the internet - WeatherReply reply(RunQuery(id, 7)); + WeatherReply reply(RunQuery(wszID, 7)); if (!reply) return reply.error(); @@ -478,6 +470,34 @@ int CWeatherProto::GetWeatherData(MCONTACT hContact) } ///////////////////////////////////////////////////////////////////////////////////////// + +static int enumSettings(const char *pszSetting, void *param) +{ + auto *pList = (OBJLIST<char>*)param; + if (!pList->find((char*)pszSetting)) + pList->insert(newStr(pszSetting)); + return 0; +} + +void CWeatherProto::GetVarsDescr(CMStringW &wszDescr) +{ + OBJLIST<char> vars(10, strcmp); + for (int i = 1; i <= 7; i++) + vars.insert(newStr(CMStringA(FORMAT, "Forecast Day %d", i))); + + for (auto &cc : AccContacts()) + db_enum_settings(cc, &enumSettings, WEATHERCONDITION, &vars); + + CMStringW str; + for (auto &it : vars) { + if (!str.IsEmpty()) + str.Append(L", "); + str.AppendFormat(L"%%[%S]", it); + } + wszDescr += str; +} + +///////////////////////////////////////////////////////////////////////////////////////// // main auto-update timer void CWeatherProto::DoUpdate() diff --git a/protocols/Weather/src/weather_userinfo.cpp b/protocols/Weather/src/weather_userinfo.cpp index 0679ddf6e9..1207d01b4a 100644 --- a/protocols/Weather/src/weather_userinfo.cpp +++ b/protocols/Weather/src/weather_userinfo.cpp @@ -151,8 +151,6 @@ public: { m_list.DeleteAllItems(); - wchar_t str[4096]; - // load weather information from the contact into the WEATHERINFO struct WEATHERINFO winfo = m_proto->LoadWeatherInfo(hContact); // check if data exist. If not, display error message box @@ -160,13 +158,11 @@ public: SetDlgItemTextW(m_hwnd, IDC_MTEXT, TranslateT("No information available.\r\nPlease update weather condition first.")); else { // set the display text and show the message box - GetDisplay(&winfo, m_proto->GetTextValue('B'), str); - SetDlgItemTextW(m_hwnd, IDC_MTEXT, str); + SetDlgItemTextW(m_hwnd, IDC_MTEXT, GetDisplay(&winfo, m_proto->GetTextValue('B'))); } - GetDisplay(&winfo, L"%c, %t", str); SetWindowTextW(m_hwnd, winfo.city); - SetDlgItemTextW(m_hwnd, IDC_HEADERBAR, str); + SetDlgItemTextW(m_hwnd, IDC_HEADERBAR, GetDisplay(&winfo, L"%c, %t")); // get all the settings and store them in a temporary list LIST<char> arSettings(10); @@ -311,9 +307,8 @@ public: ppro = (CWeatherProto *)Proto_GetContactInstance(m_hContact); // load weather info for the contact - wchar_t str[MAX_TEXT_SIZE]; WEATHERINFO w = ppro->LoadWeatherInfo(m_hContact); - SetDlgItemText(m_hwnd, IDC_INFO1, GetDisplay(&w, TranslateT("Current condition for %n"), str)); + SetDlgItemText(m_hwnd, IDC_INFO1, GetDisplay(&w, TranslateT("Current condition for %n"))); SendDlgItemMessage(m_hwnd, IDC_INFOICON, STM_SETICON, (WPARAM)ppro->GetStatusIconBig(m_hContact), 0); @@ -327,19 +322,16 @@ public: SendDlgItemMessage(m_hwnd, IDC_INFO2, WM_SETFONT, (WPARAM)CreateFontIndirect(&lf), 0); // set the text for displaying other current weather conditions data - GetDisplay(&w, L"%c %t", str); - SetDlgItemText(m_hwnd, IDC_INFO2, str); + SetDlgItemText(m_hwnd, IDC_INFO2, GetDisplay(&w, L"%c %t")); SetDlgItemText(m_hwnd, IDC_INFO3, w.feel); SetDlgItemText(m_hwnd, IDC_INFO4, w.pressure); - GetDisplay(&w, L"%i %w", str); - SetDlgItemText(m_hwnd, IDC_INFO5, str); + SetDlgItemText(m_hwnd, IDC_INFO5, GetDisplay(&w, L"%i %w")); SetDlgItemText(m_hwnd, IDC_INFO6, w.dewpoint); SetDlgItemText(m_hwnd, IDC_INFO7, w.sunrise); SetDlgItemText(m_hwnd, IDC_INFO8, w.sunset); SetDlgItemText(m_hwnd, IDC_INFO9, w.high); SetDlgItemText(m_hwnd, IDC_INFO10, w.low); - GetDisplay(&w, TranslateT("Last update on: %u"), str); - SetDlgItemText(m_hwnd, IDC_INFO11, str); + SetDlgItemText(m_hwnd, IDC_INFO11, GetDisplay(&w, TranslateT("Last update on: %u"))); SetDlgItemText(m_hwnd, IDC_INFO12, w.humid); SetDlgItemText(m_hwnd, IDC_INFO13, w.vis); return true; |
