diff options
author | George Hazan <ghazan@miranda.im> | 2021-04-30 20:07:59 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2021-04-30 20:07:59 +0300 |
commit | eddff12b3a5b0727ad84d8982f1a39df8e771b10 (patch) | |
tree | d9cdbdcd67e3d54ac767d76594766a9368b455dc /protocols/Weather | |
parent | 54ad36ab7242633de16f98f8df07a3572cb15215 (diff) |
fixes #2854 (Weather: некоторые строки не переводятся при смене ленгпака на лету)
Diffstat (limited to 'protocols/Weather')
-rw-r--r-- | protocols/Weather/src/stdafx.h | 29 | ||||
-rw-r--r-- | protocols/Weather/src/weather.cpp | 1 | ||||
-rw-r--r-- | protocols/Weather/src/weather_opt.cpp | 277 | ||||
-rw-r--r-- | protocols/Weather/src/weather_popup.cpp | 48 | ||||
-rw-r--r-- | protocols/Weather/src/weather_update.cpp | 12 | ||||
-rw-r--r-- | protocols/Weather/src/weather_userinfo.cpp | 2 |
6 files changed, 128 insertions, 241 deletions
diff --git a/protocols/Weather/src/stdafx.h b/protocols/Weather/src/stdafx.h index 6436d766b9..2d558ae68a 100644 --- a/protocols/Weather/src/stdafx.h +++ b/protocols/Weather/src/stdafx.h @@ -165,16 +165,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. // 505 HTTP Version Not Supported // defaults constants -#define C_DEFAULT L"%n [%t, %c]" -#define N_DEFAULT TranslateT("%c\\nTemperature: %t\\nFeel-Like: %f\\nPressure: %p\\nWind: %i %w\\nHumidity: %m\\nDew Point: %e\\nVisibility: %v\\n\\nSun Rise: %r\\nSun Set: %y\\n\\n5 Days Forecast:\\n%[Forecast Day 1]\\n%[Forecast Day 2]\\n%[Forecast Day 3]\\n%[Forecast Day 4]\\n%[Forecast Day 5]") -#define B_DEFAULT TranslateT("Feel-Like: %f\\nPressure: %p\\nWind: %i %w\\nHumidity: %m\\nDew Point: %e\\nVisibility: %v\\n\\nSun Rise: %r\\nSun Set: %y\\n\\n5 Days Forecast:\\n%[Forecast Day 1]\\n%[Forecast Day 2]\\n%[Forecast Day 3]\\n%[Forecast Day 4]\\n%[Forecast Day 5]") -#define b_DEFAULT TranslateT("Weather Condition for %n as of %u") -#define X_DEFAULT N_DEFAULT -#define H_DEFAULT TranslateT("%c, %t (feel-like %f) Wind: %i %w Humidity: %m") -#define E_DEFAULT TranslateT("%n at %u: %c, %t (feel-like %f) Wind: %i %w Humidity: %m") -#define P_DEFAULT TranslateT("%n (%u)") -#define p_DEFAULT TranslateT("%c, %t\\nToday: High %h, Low %l") -#define s_DEFAULT TranslateT("Temperature: %[Temperature]") #define VAR_LIST_POPUP TranslateT("%c\tcurrent condition\n%d\tcurrent date\n%e\tdewpoint\n%f\tfeel-like temperature\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") #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") #define WEATHER_NO_INFO TranslateT("No information available.\r\nPlease update weather condition first.") @@ -211,16 +201,6 @@ struct MYOPTIONS BYTE DoNotAppendUnit; BYTE NoFrac; - // texts - wchar_t *cText; - wchar_t *bTitle; - wchar_t *bText; - wchar_t *nText; - wchar_t *eText; - wchar_t *hText; - wchar_t *xText; - wchar_t *sText; - // advanced BYTE DisCondIcon; @@ -243,17 +223,11 @@ struct MYOPTIONS // popup delay DWORD pDelay; - // popup texts - wchar_t *pTitle; - wchar_t *pText; - // other misc stuff wchar_t Default[64]; MCONTACT DefStn; }; -void DestroyOptions(void); - //============ STRUCT USED TO MAKE AN UPDATE LIST ============ struct WCONTACTLIST { MCONTACT hContact; @@ -469,12 +443,13 @@ void GetINIInfo(wchar_t *pszSvc); void MoreVarList(); // functions in weather_opt.c -void SetTextDefault(const char* in); void LoadOptions(); void SaveOptions(); int OptInit(WPARAM wParam,LPARAM lParam); +CMStringW GetTextValue(int c); +const wchar_t* GetDefaultText(int c); // functions in weather_popup.c int WeatherPopup(WPARAM wParam, LPARAM lParam); diff --git a/protocols/Weather/src/weather.cpp b/protocols/Weather/src/weather.cpp index 812e0ce26c..4eafadbad7 100644 --- a/protocols/Weather/src/weather.cpp +++ b/protocols/Weather/src/weather.cpp @@ -220,7 +220,6 @@ int CMPlugin::Unload() Netlib_CloseHandle(hNetlibUser); DestroyUpdateList(); - DestroyOptions(); DestroyWIList(); // unload all ini data from memory WindowList_Destroy(hDataWindowList); diff --git a/protocols/Weather/src/weather_opt.cpp b/protocols/Weather/src/weather_opt.cpp index edadf953fa..8422c28370 100644 --- a/protocols/Weather/src/weather_opt.cpp +++ b/protocols/Weather/src/weather_opt.cpp @@ -28,70 +28,54 @@ static BOOL opt_startup; int RedrawFrame(WPARAM wParam, LPARAM lParam); //============ LOADING AND SAVING OPTIONS =========== -// -// set a string to default -// in = string to determine which field to set default "CBNEHXPp" -void SetTextDefault(const char* in) -{ - wchar_t str[MAX_TEXT_SIZE]; - if (strchr(in, 'C') != nullptr) { - wcsncpy(str, C_DEFAULT, MAX_TEXT_SIZE - 1); - wSetData(&opt.cText, str); - } - if (strchr(in, 'b') != nullptr) { - wcsncpy(str, b_DEFAULT, MAX_TEXT_SIZE - 1); - wSetData(&opt.bTitle, str); - } - if (strchr(in, 'B') != nullptr) { - wcsncpy(str, B_DEFAULT, MAX_TEXT_SIZE - 1); - wSetData(&opt.bText, str); - } - if (strchr(in, 'N') != nullptr) { - wcsncpy(str, N_DEFAULT, MAX_TEXT_SIZE - 1); - wSetData(&opt.nText, str); - } - if (strchr(in, 'E') != nullptr) { - wcsncpy(str, E_DEFAULT, MAX_TEXT_SIZE - 1); - wSetData(&opt.eText, str); - } - if (strchr(in, 'H') != nullptr) { - wcsncpy(str, H_DEFAULT, MAX_TEXT_SIZE - 1); - wSetData(&opt.hText, str); - } - if (strchr(in, 'X') != nullptr) { - wcsncpy(str, X_DEFAULT, MAX_TEXT_SIZE - 1); - wSetData(&opt.xText, str); - } - if (strchr(in, 'P') != nullptr) { - wcsncpy(str, P_DEFAULT, MAX_TEXT_SIZE - 1); - wSetData(&opt.pTitle, str); - } - if (strchr(in, 'p') != nullptr) { - wcsncpy(str, p_DEFAULT, MAX_TEXT_SIZE - 1); - wSetData(&opt.pText, str); - } - if (strchr(in, 'S') != nullptr) { - wcsncpy(str, s_DEFAULT, MAX_TEXT_SIZE - 1); - wSetData(&opt.sText, str); +const wchar_t* GetDefaultText(int c) +{ + switch (c) { + case 'C': + return L"%n [%t, %c]"; + case 'b': + return TranslateT("Weather Condition for %n as of %u"); + case 'B': + return TranslateT("Feel-Like: %f\\nPressure: %p\\nWind: %i %w\\nHumidity: %m\\nDew Point: %e\\nVisibility: %v\\n\\nSun Rise: %r\\nSun Set: %y\\n\\n5 Days Forecast:\\n%[Forecast Day 1]\\n%[Forecast Day 2]\\n%[Forecast Day 3]\\n%[Forecast Day 4]\\n%[Forecast Day 5]"); + case 'X': case 'N': + return TranslateT("%c\\nTemperature: %t\\nFeel-Like: %f\\nPressure: %p\\nWind: %i %w\\nHumidity: %m\\nDew Point: %e\\nVisibility: %v\\n\\nSun Rise: %r\\nSun Set: %y\\n\\n5 Days Forecast:\\n%[Forecast Day 1]\\n%[Forecast Day 2]\\n%[Forecast Day 3]\\n%[Forecast Day 4]\\n%[Forecast Day 5]"); + case 'E': + return TranslateT("%n at %u: %c, %t (feel-like %f) Wind: %i %w Humidity: %m"); + case 'H': + return TranslateT("%c, %t (feel-like %f) Wind: %i %w Humidity: %m"); + case 'S': + return TranslateT("Temperature: %[Temperature]"); + case 'P': + return TranslateT("%n (%u)"); + case 'p': + return TranslateT("%c, %t\\nToday: High %h, Low %l"); } + return L""; } -void DestroyOptions(void) +CMStringW GetTextValue(int c) { - wfree(&opt.cText); - wfree(&opt.bTitle); - wfree(&opt.bText); - wfree(&opt.nText); - wfree(&opt.eText); - wfree(&opt.hText); - wfree(&opt.xText); - wfree(&opt.pTitle); - wfree(&opt.pText); - wfree(&opt.sText); + CMStringW ret; + + switch (c) { + case 'C': ret = g_plugin.getMStringW("DisplayText"); break; + case 'b': ret = g_plugin.getMStringW("BriefTextTitle"); break; + case 'B': ret = g_plugin.getMStringW("BriefText"); break; + case 'N': ret = g_plugin.getMStringW("NoteText"); break; + case 'E': ret = g_plugin.getMStringW("ExtText"); break; + case 'H': ret = g_plugin.getMStringW("HistoryText"); break; + case 'X': ret = g_plugin.getMStringW("ExtraText"); break; + case 'S': ret = g_plugin.getMStringW("StatusText"); break; + case 'P': ret = g_plugin.getMStringW("PopupTitle"); break; + case 'p': ret = g_plugin.getMStringW("PopupText"); break; + } + + return (ret.IsEmpty()) ? GetDefaultText(c) : ret; } // load options from database + set default if the setting does not exist + void LoadOptions(void) { memset(&opt, 0, sizeof(opt)); @@ -120,47 +104,6 @@ void LoadOptions(void) opt.DoNotAppendUnit = g_plugin.getByte("DoNotAppendUnit", 0); opt.NoFrac = g_plugin.getByte("NoFractions", 0); - // texts - if (szValue = g_plugin.getWStringA("DisplayText")) - wSetData(&opt.cText, TranslateW(szValue)); - else - SetTextDefault("C"); - - if (szValue = g_plugin.getWStringA("BriefTextTitle")) - wSetData(&opt.bTitle, TranslateW(szValue)); - else - SetTextDefault("b"); - - if (szValue = g_plugin.getWStringA("BriefText")) - wSetData(&opt.bText, TranslateW(szValue)); - else - SetTextDefault("B"); - - if (szValue = g_plugin.getWStringA("NoteText")) - wSetData(&opt.nText, TranslateW(szValue)); - else - SetTextDefault("N"); - - if (szValue = g_plugin.getWStringA("ExtText")) - wSetData(&opt.eText, TranslateW(szValue)); - else - SetTextDefault("E"); - - if (szValue = g_plugin.getWStringA("HistoryText")) - wSetData(&opt.hText, TranslateW(szValue)); - else - SetTextDefault("H"); - - if (szValue = g_plugin.getWStringA("ExtraText")) - wSetData(&opt.xText, TranslateW(szValue)); - else - SetTextDefault("X"); - - if (szValue = g_plugin.getWStringA("StatusText")) - wSetData(&opt.sText, TranslateW(szValue)); - else - SetTextDefault("S"); - // advanced opt.DisCondIcon = g_plugin.getByte("DisableConditionIcon", false); // popup options @@ -178,16 +121,6 @@ void LoadOptions(void) opt.RightClickAction = g_plugin.getDword("RightClickAction", IDM_M1); // popup delay opt.pDelay = g_plugin.getDword("PopupDelay", 0); - // popup texts - if (szValue = g_plugin.getWStringA("PopupTitle")) - wSetData(&opt.pTitle, szValue); - else - SetTextDefault("P"); - - if (szValue = g_plugin.getWStringA("PopupText")) - wSetData(&opt.pText, szValue); - else - SetTextDefault("p"); // misc if (szValue = g_plugin.getWStringA("Default")) @@ -218,15 +151,6 @@ void SaveOptions(void) g_plugin.setWString("DegreeSign", opt.DegreeSign); g_plugin.setByte("DoNotAppendUnit", (BYTE)opt.DoNotAppendUnit); g_plugin.setByte("NoFractions", (BYTE)opt.NoFrac); - // texts - g_plugin.setWString("DisplayText", opt.cText); - g_plugin.setWString("BriefTextTitle", opt.bTitle); - g_plugin.setWString("BriefText", opt.bText); - g_plugin.setWString("NoteText", opt.nText); - g_plugin.setWString("ExtText", opt.eText); - g_plugin.setWString("HistoryText", opt.hText); - g_plugin.setWString("ExtraText", opt.xText); - g_plugin.setWString("StatusText", opt.sText); // advanced g_plugin.setByte("DisableConditionIcon", (BYTE)opt.DisCondIcon); // popup options @@ -244,9 +168,6 @@ void SaveOptions(void) g_plugin.setDword("RightClickAction", opt.RightClickAction); // popup delay g_plugin.setDword("PopupDelay", opt.pDelay); - // popup texts - g_plugin.setWString("PopupTitle", opt.pTitle); - g_plugin.setWString("PopupText", opt.pText); // misc stuff g_plugin.setWString("Default", opt.Default); } @@ -387,37 +308,25 @@ static INT_PTR CALLBACK OptionsProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM l //============ TEXT OPTION DIALOG ============ -static void LoadTextSettings(HWND hdlg) -{ - // load text option settings from memory - SetDlgItemText(hdlg, IDC_CTEXT, opt.cText); - SetDlgItemText(hdlg, IDC_BTITLE, opt.bTitle); - SetDlgItemText(hdlg, IDC_BTEXT, opt.bText); - SetDlgItemText(hdlg, IDC_ETEXT, opt.eText); - SetDlgItemText(hdlg, IDC_NTEXT, opt.nText); - SetDlgItemText(hdlg, IDC_HTEXT, opt.hText); - SetDlgItemText(hdlg, IDC_XTEXT, opt.xText); - SetDlgItemText(hdlg, IDC_BTITLE2, opt.sText); -} +// text option dialog -// free the display text settings from memory -static void FreeTextVar(void) +struct { - wfree(&opt.cText); - wfree(&opt.bText); - wfree(&opt.bTitle); - wfree(&opt.eText); - wfree(&opt.nText); - wfree(&opt.hText); - wfree(&opt.xText); - wfree(&opt.sText); + wchar_t c; + int id; + char *setting; } - -// text option dialog - -static const char *varname[8] = { "C", "b", "B", "N", "X", "E", "H", "S" }; -static const int cname[8] = { IDC_CTEXT, IDC_BTITLE, IDC_BTEXT, IDC_NTEXT, IDC_XTEXT, IDC_ETEXT, IDC_HTEXT, IDC_BTITLE2 }; -static wchar_t* const *var[8] = { &opt.cText, &opt.bTitle, &opt.bText, &opt.nText, &opt.xText, &opt.eText, &opt.hText, &opt.sText }; +static controls[] = +{ + { 'C', IDC_CTEXT, "DisplayText" }, + { 'b', IDC_BTITLE, "BriefTextTitle" }, + { 'B', IDC_BTEXT, "BriefText" }, + { 'N', IDC_NTEXT, "NoteText" }, + { 'X', IDC_XTEXT, "ExtText" }, + { 'E', IDC_ETEXT, "HistoryText" }, + { 'H', IDC_HTEXT, "ExtraText" }, + { 'S', IDC_BTITLE2, "StatusText" }, +}; static INT_PTR CALLBACK DlgProcText(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam) { @@ -432,10 +341,14 @@ static INT_PTR CALLBACK DlgProcText(HWND hdlg, UINT msg, WPARAM wParam, LPARAM l GetWindowRect(hdlg, &rc); SetWindowPos(hdlg, HWND_TOPMOST, rc.left, rc.top, 0, 0, SWP_NOSIZE); TranslateDialogDefault(hdlg); + // generate the display text for variable list wcsncpy(str, VAR_LIST_OPT, _countof(str) - 1); SetDlgItemText(hdlg, IDC_VARLIST, str); + for (auto &it : controls) + SetDlgItemText(hdlg, it.id, GetTextValue(it.c)); + // make the more variable and other buttons flat SendDlgItemMessage(hdlg, IDC_MORE, BUTTONSETASFLATBTN, TRUE, 0); SendDlgItemMessage(hdlg, IDC_TM1, BUTTONSETASFLATBTN, TRUE, 0); @@ -447,8 +360,8 @@ static INT_PTR CALLBACK DlgProcText(HWND hdlg, UINT msg, WPARAM wParam, LPARAM l SendDlgItemMessage(hdlg, IDC_TM7, BUTTONSETASFLATBTN, TRUE, 0); SendDlgItemMessage(hdlg, IDC_TM8, BUTTONSETASFLATBTN, TRUE, 0); SendDlgItemMessage(hdlg, IDC_RESET, BUTTONSETASFLATBTN, TRUE, 0); + // load the settings - LoadTextSettings(hdlg); opt_startup = FALSE; return TRUE; @@ -486,25 +399,26 @@ static INT_PTR CALLBACK DlgProcText(HWND hdlg, UINT msg, WPARAM wParam, LPARAM l hMenu = LoadMenu(g_plugin.getInst(), MAKEINTRESOURCE(IDR_TMMENU)); hMenu1 = GetSubMenu(hMenu, 0); TranslateMenu(hMenu1); - switch (TrackPopupMenu(hMenu1, TPM_LEFTBUTTON | TPM_RETURNCMD, pos.left, pos.bottom, 0, hdlg, nullptr)) { - case ID_MPREVIEW: - { - // show the preview in a message box, using the weather data from the default station - WEATHERINFO winfo = LoadWeatherInfo(opt.DefStn); - GetDisplay(&winfo, *var[LOWORD(wParam) - IDC_TM1], str); - MessageBox(nullptr, str, TranslateT("Weather Protocol Text Preview"), MB_OK | MB_TOPMOST); + { + auto &var = controls[int(LOWORD(wParam)) - IDC_TM1]; + + switch (TrackPopupMenu(hMenu1, TPM_LEFTBUTTON | TPM_RETURNCMD, pos.left, pos.bottom, 0, hdlg, nullptr)) { + case ID_MPREVIEW: + { + // show the preview in a message box, using the weather data from the default station + WEATHERINFO winfo = LoadWeatherInfo(opt.DefStn); + wchar_t buf[2] = { var.c, 0 }; + GetDisplay(&winfo, buf, str); + MessageBox(nullptr, str, TranslateT("Weather Protocol Text Preview"), MB_OK | MB_TOPMOST); + } + break; + + case ID_MRESET: + SetDlgItemText(hdlg, var.id, GetDefaultText(var.c)); break; } - case ID_MRESET: - unsigned varo = LOWORD(wParam) - IDC_TM1; - // remove the old setting from db and free memory - wchar_t* vartmp = *var[varo]; - wfree(&vartmp); - SetTextDefault(varname[varo]); - SetDlgItemText(hdlg, cname[varo], *var[varo]); - break; + DestroyMenu(hMenu); } - DestroyMenu(hMenu); break; case IDC_RESET: @@ -517,14 +431,14 @@ static INT_PTR CALLBACK DlgProcText(HWND hdlg, UINT msg, WPARAM wParam, LPARAM l switch (TrackPopupMenu(hMenu1, TPM_LEFTBUTTON | TPM_RETURNCMD, pos.left, pos.bottom, 0, hdlg, nullptr)) { case ID_T1: // reset to the strings in memory, discard all changes - LoadTextSettings(hdlg); + for (auto &it : controls) + SetDlgItemText(hdlg, it.id, GetTextValue(it.c)); break; case ID_T2: // reset to the default setting - FreeTextVar(); - SetTextDefault("CbBENHX"); - LoadTextSettings(hdlg); + for (auto &it : controls) + SetDlgItemText(hdlg, it.id, GetDefaultText(it.c)); break; } DestroyMenu(hMenu); @@ -536,25 +450,14 @@ static INT_PTR CALLBACK DlgProcText(HWND hdlg, UINT msg, WPARAM wParam, LPARAM l case PSN_APPLY: // save the option wchar_t textstr[MAX_TEXT_SIZE]; - // free memory for old settings - FreeTextVar(); - // save new settings to memory - GetDlgItemText(hdlg, IDC_CTEXT, textstr, _countof(textstr)); - wSetData(&opt.cText, textstr); - GetDlgItemText(hdlg, IDC_BTEXT, textstr, _countof(textstr)); - wSetData(&opt.bText, textstr); - GetDlgItemText(hdlg, IDC_BTITLE, textstr, _countof(textstr)); - wSetData(&opt.bTitle, textstr); - GetDlgItemText(hdlg, IDC_ETEXT, textstr, _countof(textstr)); - wSetData(&opt.eText, textstr); - GetDlgItemText(hdlg, IDC_NTEXT, textstr, _countof(textstr)); - wSetData(&opt.nText, textstr); - GetDlgItemText(hdlg, IDC_HTEXT, textstr, _countof(textstr)); - wSetData(&opt.hText, textstr); - GetDlgItemText(hdlg, IDC_XTEXT, textstr, _countof(textstr)); - wSetData(&opt.xText, textstr); - GetDlgItemText(hdlg, IDC_BTITLE2, textstr, _countof(textstr)); - wSetData(&opt.sText, textstr); + for (auto &it : controls) { + GetDlgItemText(hdlg, it.id, textstr, _countof(textstr)); + if (!mir_wstrcmpi(textstr, GetDefaultText(it.c))) + g_plugin.delSetting(it.setting); + else + g_plugin.setWString(it.setting, textstr); + } + SaveOptions(); UpdateAllInfo(0, 0); break; diff --git a/protocols/Weather/src/weather_popup.cpp b/protocols/Weather/src/weather_popup.cpp index b19d36f67e..5f2ca4ac3b 100644 --- a/protocols/Weather/src/weather_popup.cpp +++ b/protocols/Weather/src/weather_popup.cpp @@ -132,8 +132,8 @@ int WeatherPopup(WPARAM hContact, LPARAM lParam) POPUPDATAW ppd; ppd.lchContact = hContact; ppd.PluginData = ppd.lchIcon = Skin_LoadProtoIcon(MODULENAME, winfo.status); - GetDisplay(&winfo, opt.pTitle, ppd.lpwzContactName); - GetDisplay(&winfo, opt.pText, ppd.lpwzText); + GetDisplay(&winfo, GetTextValue('P'), ppd.lpwzContactName); + GetDisplay(&winfo, GetTextValue('p'), ppd.lpwzText); ppd.PluginWindowProc = PopupDlgProc; ppd.colorBack = (opt.UseWinColors) ? GetSysColor(COLOR_BTNFACE) : opt.BGColour; ppd.colorText = (opt.UseWinColors) ? GetSysColor(COLOR_WINDOWTEXT) : opt.TextColour; @@ -199,6 +199,18 @@ LRESULT CALLBACK PopupWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam //============ POPUP OPTIONS ============ +struct +{ + wchar_t c; + int id; + char *setting; +} +static controls[] = +{ + { 'p', IDC_PText, "PopupText" }, + { 'P', IDC_PTitle, "PopupTitle" }, +}; + // used to select the menu item for popup action menu static void SelectMenuItem(HMENU hMenu, int Check) { @@ -210,7 +222,6 @@ static void SelectMenuItem(HMENU hMenu, int Check) // but does not write to the database void ReadPopupOpt(HWND hdlg) { - wchar_t text[MAX_TEXT_SIZE]; wchar_t str[512]; // popup colour @@ -229,14 +240,6 @@ void ReadPopupOpt(HWND hdlg) opt.AlertPopup = (BYTE)IsDlgButtonChecked(hdlg, IDC_POP2); opt.PopupOnChange = (BYTE)IsDlgButtonChecked(hdlg, IDC_CH); opt.ShowWarnings = (BYTE)IsDlgButtonChecked(hdlg, IDC_W); - - // popup texts - wfree(&opt.pText); - wfree(&opt.pTitle); - GetDlgItemText(hdlg, IDC_PText, text, _countof(text)); - wSetData(&opt.pText, text); - GetDlgItemText(hdlg, IDC_PTitle, text, _countof(text)); - wSetData(&opt.pTitle, text); } // copied and modified from NewStatusNotify @@ -269,8 +272,10 @@ INT_PTR CALLBACK DlgPopupOpts(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam) CheckDlgButton(hdlg, IDC_POP1, opt.UpdatePopup ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hdlg, IDC_CH, opt.PopupOnChange ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hdlg, IDC_W, opt.ShowWarnings ? BST_CHECKED : BST_UNCHECKED); - SetDlgItemText(hdlg, IDC_PText, opt.pText); - SetDlgItemText(hdlg, IDC_PTitle, opt.pTitle); + + for (auto &it : controls) + SetDlgItemText(hdlg, it.id, GetTextValue(it.c)); + // setting popup delay option _ltow(opt.pDelay, str, 10); SetDlgItemText(hdlg, IDC_DELAY, str); @@ -384,11 +389,8 @@ INT_PTR CALLBACK DlgPopupOpts(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam) case IDC_PDEF: // set the default value for popup texts - SetTextDefault("Pp"); - SetDlgItemText(hdlg, IDC_PText, opt.pText); - SetDlgItemText(hdlg, IDC_PTitle, opt.pTitle); - wfree(&opt.pText); - wfree(&opt.pTitle); + for (auto &it : controls) + SetDlgItemText(hdlg, it.id, GetDefaultText(it.c)); break; case IDC_VAR3: @@ -405,7 +407,6 @@ INT_PTR CALLBACK DlgPopupOpts(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam) hContact = opt.DefStn; ReadPopupOpt(hdlg); // read new options to memory WeatherPopup((WPARAM)opt.DefStn, (BOOL)TRUE); // display popup using new opt - DestroyOptions(); LoadOptions(); // restore old option in memory opt.DefStn = hContact; break; @@ -417,6 +418,15 @@ INT_PTR CALLBACK DlgPopupOpts(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam) case PSN_APPLY: ReadPopupOpt(hdlg); + wchar_t textstr[MAX_TEXT_SIZE]; + for (auto &it : controls) { + GetDlgItemText(hdlg, it.id, textstr, _countof(textstr)); + if (!mir_wstrcmpi(textstr, GetDefaultText(it.c))) + g_plugin.delSetting(it.setting); + else + g_plugin.setWString(it.setting, textstr); + } + // save the options, and update main menu SaveOptions(); UpdatePopupMenu(opt.UsePopup); diff --git a/protocols/Weather/src/weather_update.cpp b/protocols/Weather/src/weather_update.cpp index 1701b25868..7c36bebe99 100644 --- a/protocols/Weather/src/weather_update.cpp +++ b/protocols/Weather/src/weather_update.cpp @@ -129,10 +129,10 @@ int UpdateWeather(MCONTACT hContact) g_plugin.setWord(hContact, "Status", winfo.status); AvatarDownloaded(hContact); - GetDisplay(&winfo, opt.cText, str2); + GetDisplay(&winfo, GetTextValue('C'), str2); db_set_ws(hContact, "CList", "MyHandle", str2); - GetDisplay(&winfo, opt.sText, str2); + GetDisplay(&winfo, GetTextValue('S'), str2); if (str2[0]) db_set_ws(hContact, "CList", "StatusMsg", str2); else @@ -141,9 +141,9 @@ int UpdateWeather(MCONTACT hContact) ProtoBroadcastAck(MODULENAME, hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, nullptr, (LPARAM)(str2[0] ? str2 : nullptr)); // save descriptions in MyNotes - GetDisplay(&winfo, opt.nText, str2); + GetDisplay(&winfo, GetTextValue('N'), str2); db_set_ws(hContact, "UserInfo", "MyNotes", str2); - GetDisplay(&winfo, opt.xText, str2); + GetDisplay(&winfo, GetTextValue('X'), str2); db_set_ws(hContact, WEATHERCONDITION, "WeatherInfo", str2); // set the update tag @@ -176,7 +176,7 @@ int UpdateWeather(MCONTACT hContact) db_free(&dbv); if (file != nullptr) { // write data to the file and close - GetDisplay(&winfo, opt.eText, str2); + GetDisplay(&winfo, GetTextValue('E'), str2); fputws(str2, file); fclose(file); } @@ -185,7 +185,7 @@ int UpdateWeather(MCONTACT hContact) if (g_plugin.getByte(hContact, "History")) { // internal log using history - GetDisplay(&winfo, opt.hText, str2); + GetDisplay(&winfo, GetTextValue('H'), str2); T2Utf szMessage(str2); diff --git a/protocols/Weather/src/weather_userinfo.cpp b/protocols/Weather/src/weather_userinfo.cpp index 3ce9460c1b..c30647a4e4 100644 --- a/protocols/Weather/src/weather_userinfo.cpp +++ b/protocols/Weather/src/weather_userinfo.cpp @@ -64,7 +64,7 @@ static void LoadBriefInfoText(HWND hwndDlg, MCONTACT hContact) wcsncpy(str, WEATHER_NO_INFO, _countof(str) - 1); else // set the display text and show the message box - GetDisplay(&winfo, opt.bText, str); + GetDisplay(&winfo, GetTextValue('B'), str); SetDlgItemText(hwndDlg, IDC_MTEXT, str); GetDisplay(&winfo, L"%c, %t", str); |