From 79412831126e49d990a44506af1ae69f78797d6c Mon Sep 17 00:00:00 2001 From: Tobias Weimer Date: Thu, 24 Mar 2016 23:32:20 +0000 Subject: Weather: - minor fixes git-svn-id: http://svn.miranda-ng.org/main/trunk@16539 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Weather/src/stdafx.h | 16 +----- plugins/Weather/src/weather_contacts.cpp | 57 +++++++++++----------- plugins/Weather/src/weather_http.cpp | 20 +++++--- plugins/Weather/src/weather_ini.cpp | 6 +-- plugins/Weather/src/weather_mwin.cpp | 6 ++- plugins/Weather/src/weather_opt.cpp | 83 ++++++++++++++++---------------- plugins/Weather/src/weather_popup.cpp | 55 +++++++++++---------- plugins/Weather/src/weather_update.cpp | 3 +- 8 files changed, 118 insertions(+), 128 deletions(-) (limited to 'plugins/Weather/src') diff --git a/plugins/Weather/src/stdafx.h b/plugins/Weather/src/stdafx.h index dd86dfc4fc..43a6d19eed 100644 --- a/plugins/Weather/src/stdafx.h +++ b/plugins/Weather/src/stdafx.h @@ -397,15 +397,12 @@ INT_PTR LoadForecast(WPARAM wParam,LPARAM lParam); INT_PTR WeatherMap(WPARAM wParam,LPARAM lParam); INT_PTR EditSettings(WPARAM wParam,LPARAM lParam); -INT_PTR CALLBACK DlgProcChange(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); int ContactDeleted(WPARAM wParam,LPARAM lParam); BOOL IsMyContact(MCONTACT hContact); // functions in weather_conv.c -BOOL is_number(char *s); - void GetTemp(TCHAR *tempchar, TCHAR *unit, TCHAR *str); void GetSpeed(TCHAR *tempchar, TCHAR *unit, TCHAR *str); void GetPressure(TCHAR *tempchar, TCHAR *unit, TCHAR *str); @@ -462,6 +459,7 @@ bool LoadWIData(bool dial); void FreeWIData(WIDATA *Data); INT_PTR CALLBACK DlgProcSetup(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); +INT_PTR CALLBACK DlgPopupOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); // functions in weather_info.c void GetINIInfo(TCHAR *pszSvc); @@ -475,21 +473,12 @@ void SaveOptions(); int OptInit(WPARAM wParam,LPARAM lParam); -INT_PTR CALLBACK OptionsProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lparam); -void SetIconDefault(); -void RemoveIconSettings(); - -BOOL CALLBACK TextOptionsProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lparam); -BOOL CALLBACK AdvOptionsProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lparam); -INT_PTR CALLBACK DlgProcText(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); -INT_PTR CALLBACK DlgPopupOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); // functions in weather_popup.c int WeatherPopup(WPARAM wParam, LPARAM lParam); int WeatherError(WPARAM wParam, LPARAM lParam); int WPShowMessage(TCHAR* lpzText, WORD kind); -LRESULT CALLBACK PopupDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); LRESULT CALLBACK PopupWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); // functions in weather_svcs.c @@ -509,8 +498,6 @@ void AvatarDownloaded(MCONTACT hContact); // functions in weather_update.c int UpdateWeather(MCONTACT hContact); -int RetrieveWeather(MCONTACT hContact, WEATHERINFO *winfo); - void UpdateAll(BOOL AutoUpdate, BOOL RemoveOld); void UpdateThreadProc(LPVOID hWnd); INT_PTR UpdateSingleStation(WPARAM wParam,LPARAM lParam); @@ -542,7 +529,6 @@ INT_PTR CALLBACK DlgProcINIPage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP int BriefInfo(WPARAM wParam, LPARAM lParam); INT_PTR BriefInfoSvc(WPARAM wParam, LPARAM lParam); void LoadBriefInfoText(HWND hwndDlg, MCONTACT hContact); -INT_PTR CALLBACK DlgProcBrief(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); void InitIcons(void); HICON LoadIconEx(const char* name, bool big); diff --git a/plugins/Weather/src/weather_contacts.cpp b/plugins/Weather/src/weather_contacts.cpp index ae74ad7973..355fd7b25c 100644 --- a/plugins/Weather/src/weather_contacts.cpp +++ b/plugins/Weather/src/weather_contacts.cpp @@ -34,9 +34,9 @@ static void OpenUrl(TCHAR* format, TCHAR* id) } //============ BASIC CONTACTS FUNCTIONS AND LINKS ============ + // view weather log for the contact // wParam = current contact - INT_PTR ViewLog(WPARAM wParam, LPARAM lParam) { // see if the log path is set @@ -54,7 +54,6 @@ INT_PTR ViewLog(WPARAM wParam, LPARAM lParam) // read complete forecast // wParam = current contact - INT_PTR LoadForecast(WPARAM wParam, LPARAM) { TCHAR id[256], loc2[256]; @@ -93,27 +92,6 @@ INT_PTR WeatherMap(WPARAM wParam, LPARAM) //============ EDIT SETTINGS ============ -// show edit settings dialog -// wParam = current contact -INT_PTR EditSettings(WPARAM wParam, LPARAM) -{ - HWND hEditDlg = WindowList_Find(hWindowList, wParam); - - // search the dialog list to prevent multiple instance of dialog for the same contact - if (hEditDlg != NULL) { - // if the dialog box already opened, bring it to the front - SetForegroundWindow(hEditDlg); - SetFocus(hEditDlg); - } - else { - // if the dialog box is not opened, open a new one - if (IsMyContact(wParam)) - CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_EDIT), NULL, DlgProcChange, (LPARAM)wParam); - } - - return 0; -} - typedef struct { MCONTACT hContact; @@ -125,10 +103,10 @@ typedef struct // edit weather settings // lParam = current contact -INT_PTR CALLBACK DlgProcChange(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +static INT_PTR CALLBACK DlgProcChange(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { DBVARIANT dbv; - TCHAR str[256], str2[256], city[256], filter[256], *pfilter, *chop; + TCHAR str[MAX_DATA_LEN], str2[256], city[256], filter[256], *pfilter, *chop; char loc[512]; OPENFILENAME ofn; // common dialog box structure MCONTACT hContact; @@ -282,8 +260,8 @@ INT_PTR CALLBACK DlgProcChange(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa EnableWindow(GetDlgItem(hwndDlg, IDC_BROWSE), (BYTE)IsDlgButtonChecked(hwndDlg, IDC_External)); if (!(BYTE)IsDlgButtonChecked(hwndDlg, IDC_External)) return TRUE; - - case IDC_BROWSE: // fall through + // fall through + case IDC_BROWSE: // browse for the external log file GetDlgItemText(hwndDlg, IDC_LOG, str, _countof(str)); // Initialize OPENFILENAME @@ -396,8 +374,8 @@ INT_PTR CALLBACK DlgProcChange(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa // re-enable the protocol and update the data for the station db_set_s(hContact, WEATHERPROTONAME, "LastCondition", "None"); UpdateSingleStation(hContact, 0); - - case IDCANCEL: // fall through + // fall through + case IDCANCEL: // remove the dialog from window list and close it DestroyWindow(hwndDlg); break; @@ -425,6 +403,27 @@ INT_PTR CALLBACK DlgProcChange(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa return FALSE; } +// show edit settings dialog +// wParam = current contact +INT_PTR EditSettings(WPARAM wParam, LPARAM) +{ + HWND hEditDlg = WindowList_Find(hWindowList, wParam); + + // search the dialog list to prevent multiple instance of dialog for the same contact + if (hEditDlg != NULL) { + // if the dialog box already opened, bring it to the front + SetForegroundWindow(hEditDlg); + SetFocus(hEditDlg); + } + else { + // if the dialog box is not opened, open a new one + if (IsMyContact(wParam)) + CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_EDIT), NULL, DlgProcChange, (LPARAM)wParam); + } + + return 0; +} + //============ CONTACT DELETION ============ // when a contact is deleted, make sure some other contact take over the default station diff --git a/plugins/Weather/src/weather_http.cpp b/plugins/Weather/src/weather_http.cpp index 89cac41c2f..7d63c1ad6c 100644 --- a/plugins/Weather/src/weather_http.cpp +++ b/plugins/Weather/src/weather_http.cpp @@ -103,16 +103,20 @@ int InternetDownloadFile(char *szUrl, char *cookie, char *userAgent, TCHAR **szD char* beg = strstr(end, "'); - tmp = *end; *end = 0; - - method = strstr(beg, "http-equiv=\""); - if (method && _strnicmp(method + 12, "Content-Type", 12) == 0 && strstr(method, "utf-8")) { - bIsUtf = true; - break; + if (end) + { + char tmp = *end; + *end = 0; + + char *method = strstr(beg, "http-equiv=\""); + if (method && _strnicmp(method + 12, "Content-Type", 12) == 0 && strstr(method, "utf-8")) { + bIsUtf = true; + *end = tmp; + break; + } + else *end = tmp; } - else *end = tmp; } } } diff --git a/plugins/Weather/src/weather_ini.cpp b/plugins/Weather/src/weather_ini.cpp index 0775fff823..3d6e94b216 100644 --- a/plugins/Weather/src/weather_ini.cpp +++ b/plugins/Weather/src/weather_ini.cpp @@ -557,8 +557,8 @@ INT_PTR CALLBACK DlgProcSetup(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPar if (chop) { *chop = '\0'; mir_tstrncat(szPath, _T("\\Plugins\\weather\\"), _countof(szPath) - mir_tstrlen(szPath)); - _tmkdir(szPath); - ShellExecute((HWND)lParam, _T("open"), szPath, _T(""), _T(""), SW_SHOW); + if (_tmkdir(szPath) == 0) + ShellExecute((HWND)lParam, _T("open"), szPath, _T(""), _T(""), SW_SHOW); } break; } @@ -572,7 +572,7 @@ INT_PTR CALLBACK DlgProcSetup(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPar case IDC_STEP4: WeatherAdd(0, 0); - + // fall through case IDCANCEL: // close the info window DestroyWindow(hwndDlg); diff --git a/plugins/Weather/src/weather_mwin.cpp b/plugins/Weather/src/weather_mwin.cpp index 2dc78a8975..dd4f4f3029 100644 --- a/plugins/Weather/src/weather_mwin.cpp +++ b/plugins/Weather/src/weather_mwin.cpp @@ -167,7 +167,8 @@ static LRESULT CALLBACK wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara fntc1 = CallService(MS_FONT_GETT, (WPARAM)&fntid, (LPARAM)&lfnt1); } - db_get_ts(data->hContact, WEATHERCONDITION, "WeatherInfo", &dbv); + if (db_get_ts(data->hContact, WEATHERCONDITION, "WeatherInfo", &dbv)) + break; GetClientRect(hwnd, &rc); @@ -240,7 +241,8 @@ static LRESULT CALLBACK wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara static void addWindow(MCONTACT hContact) { DBVARIANT dbv; - db_get_ts(hContact, WEATHERPROTONAME, "Nick", &dbv); + if (db_get_ts(hContact, WEATHERPROTONAME, "Nick", &dbv)) + return; TCHAR winname[512]; mir_sntprintf(winname, _T("Weather: %s"), dbv.ptszVal); diff --git a/plugins/Weather/src/weather_opt.cpp b/plugins/Weather/src/weather_opt.cpp index 4733e8cb1d..fd36410b99 100644 --- a/plugins/Weather/src/weather_opt.cpp +++ b/plugins/Weather/src/weather_opt.cpp @@ -250,49 +250,10 @@ void SaveOptions(void) // misc stuff db_set_ts(NULL, WEATHERPROTONAME, "Default", opt.Default); } - -//============ OPTION INITIALIZATION ============ - -// register the weather option pages -int OptInit(WPARAM wParam, LPARAM) -{ - OPTIONSDIALOGPAGE odp = { 0 }; - odp.hInstance = hInst; - - // plugin options - odp.position = 95600; - odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTIONS); - odp.pfnDlgProc = OptionsProc; - odp.ptszGroup = LPGENT("Network"); - odp.ptszTitle = _T(WEATHERPROTOTEXT); - odp.ptszTab = LPGENT("General"); - odp.flags = ODPF_BOLDGROUPS | ODPF_TCHAR; - Options_AddPage(wParam, &odp); - - // text options - odp.pszTemplate = MAKEINTRESOURCEA(IDD_TEXTOPT); - odp.pfnDlgProc = DlgProcText; - odp.ptszTab = LPGENT("Display"); - Options_AddPage(wParam, &odp); - - // if popup service exists, load the weather popup options - if ((ServiceExists(MS_POPUP_ADDPOPUPT))) { - odp.position = 100000000; - odp.pszTemplate = MAKEINTRESOURCEA(IDD_POPUP); - odp.ptszGroup = LPGENT("Popups"); - odp.groupPosition = 910000000; - odp.ptszTab = NULL; - odp.pfnDlgProc = DlgPopupOpts; - Options_AddPage(wParam, &odp); - } - - return 0; -} - //============ MAIN OPTIONS ============ // weather options -INT_PTR CALLBACK OptionsProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam) +static INT_PTR CALLBACK OptionsProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam) { TCHAR str[512]; @@ -377,7 +338,7 @@ INT_PTR CALLBACK OptionsProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam) opt.UpdateTime = (WORD)_ttoi(str); if (opt.UpdateTime < 1) opt.UpdateTime = 1; KillTimer(NULL, timerId); - timerId = SetTimer(NULL, 0, opt.UpdateTime * 60000, (TIMERPROC)timerProc); + timerId = SetTimer(NULL, 0, opt.UpdateTime * 60000, timerProc); // other general options GetDlgItemText(hdlg, IDC_DEGREE, opt.DegreeSign, _countof(opt.DegreeSign)); @@ -458,7 +419,7 @@ 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 TCHAR* const *var[8] = { &opt.cText, &opt.bTitle, &opt.bText, &opt.nText, &opt.xText, &opt.eText, &opt.hText, &opt.sText }; -INT_PTR CALLBACK DlgProcText(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam) +static INT_PTR CALLBACK DlgProcText(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam) { RECT rc, pos; HWND button; @@ -603,3 +564,41 @@ INT_PTR CALLBACK DlgProcText(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam) return FALSE; } + +//============ OPTION INITIALIZATION ============ + +// register the weather option pages +int OptInit(WPARAM wParam, LPARAM) +{ + OPTIONSDIALOGPAGE odp = { 0 }; + odp.hInstance = hInst; + + // plugin options + odp.position = 95600; + odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTIONS); + odp.pfnDlgProc = OptionsProc; + odp.ptszGroup = LPGENT("Network"); + odp.ptszTitle = _T(WEATHERPROTOTEXT); + odp.ptszTab = LPGENT("General"); + odp.flags = ODPF_BOLDGROUPS | ODPF_TCHAR; + Options_AddPage(wParam, &odp); + + // text options + odp.pszTemplate = MAKEINTRESOURCEA(IDD_TEXTOPT); + odp.pfnDlgProc = DlgProcText; + odp.ptszTab = LPGENT("Display"); + Options_AddPage(wParam, &odp); + + // if popup service exists, load the weather popup options + if ((ServiceExists(MS_POPUP_ADDPOPUPT))) { + odp.position = 100000000; + odp.pszTemplate = MAKEINTRESOURCEA(IDD_POPUP); + odp.ptszGroup = LPGENT("Popups"); + odp.groupPosition = 910000000; + odp.ptszTab = NULL; + odp.pfnDlgProc = DlgPopupOpts; + Options_AddPage(wParam, &odp); + } + + return 0; +} diff --git a/plugins/Weather/src/weather_popup.cpp b/plugins/Weather/src/weather_popup.cpp index 4835761da6..5351d74abf 100644 --- a/plugins/Weather/src/weather_popup.cpp +++ b/plugins/Weather/src/weather_popup.cpp @@ -29,38 +29,12 @@ static HANDLE hPopupContact; //============ SHOW WEATHER POPUPS ============ -// display weather popups -// wParam = the contact to display popup -// lParam = whether the weather data is changed or not -int WeatherPopup(WPARAM hContact, LPARAM lParam) -{ - // determine if the popup should display or not - if (opt.UsePopup && opt.UpdatePopup && (!opt.PopupOnChange || (BOOL)lParam) && - !db_get_b(hContact, WEATHERPROTONAME, "DPopUp", 0)) { - WEATHERINFO winfo = LoadWeatherInfo(hContact); - - // setup the popup - POPUPDATAT ppd = { 0 }; - ppd.lchContact = hContact; - ppd.PluginData = ppd.lchIcon = Skin_LoadProtoIcon(WEATHERPROTONAME, winfo.status); - GetDisplay(&winfo, opt.pTitle, ppd.lptzContactName); - GetDisplay(&winfo, opt.pText, ppd.lptzText); - ppd.PluginWindowProc = PopupDlgProc; - ppd.colorBack = (opt.UseWinColors) ? GetSysColor(COLOR_BTNFACE) : opt.BGColour; - ppd.colorText = (opt.UseWinColors) ? GetSysColor(COLOR_WINDOWTEXT) : opt.TextColour; - ppd.iSeconds = opt.pDelay; - PUAddPopupT(&ppd); - } - return 0; -} - //============ WEATHER ERROR POPUPS ============ // display weather error or notices (not threaded) // wParam = error text // lParam = display type // Type can either be SM_WARNING, SM_NOTIFY, or SM_WEATHERALERT - int WeatherError(WPARAM wParam, LPARAM lParam) { if (!opt.UsePopup) @@ -107,7 +81,6 @@ int WeatherError(WPARAM wParam, LPARAM lParam) // (threaded) // lpzText = error text // kind = display type (see m_popup.h) - int WPShowMessage(TCHAR* lpzText, WORD kind) { NotifyEventHooks(hHookWeatherError, (WPARAM)lpzText, (LPARAM)kind); @@ -119,7 +92,7 @@ int WPShowMessage(TCHAR* lpzText, WORD kind) // popup dialog pocess // for selecting actions when click on the popup window // use for displaying contact menu -LRESULT CALLBACK PopupDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +static LRESULT CALLBACK PopupDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { DWORD ID = 0; MCONTACT hContact; @@ -146,6 +119,32 @@ LRESULT CALLBACK PopupDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa return DefWindowProc(hWnd, message, wParam, lParam); } +// display weather popups +// wParam = the contact to display popup +// lParam = whether the weather data is changed or not +int WeatherPopup(WPARAM hContact, LPARAM lParam) +{ + // determine if the popup should display or not + if (opt.UsePopup && opt.UpdatePopup && (!opt.PopupOnChange || (BOOL)lParam) && + !db_get_b(hContact, WEATHERPROTONAME, "DPopUp", 0)) { + WEATHERINFO winfo = LoadWeatherInfo(hContact); + + // setup the popup + POPUPDATAT ppd = { 0 }; + ppd.lchContact = hContact; + ppd.PluginData = ppd.lchIcon = Skin_LoadProtoIcon(WEATHERPROTONAME, winfo.status); + GetDisplay(&winfo, opt.pTitle, ppd.lptzContactName); + GetDisplay(&winfo, opt.pText, ppd.lptzText); + ppd.PluginWindowProc = PopupDlgProc; + ppd.colorBack = (opt.UseWinColors) ? GetSysColor(COLOR_BTNFACE) : opt.BGColour; + ppd.colorText = (opt.UseWinColors) ? GetSysColor(COLOR_WINDOWTEXT) : opt.TextColour; + ppd.iSeconds = opt.pDelay; + PUAddPopupT(&ppd); + } + return 0; +} + + // process for the popup window // containing the code for popup actions LRESULT CALLBACK PopupWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) diff --git a/plugins/Weather/src/weather_update.cpp b/plugins/Weather/src/weather_update.cpp index a01a2d19fe..b2d2928896 100644 --- a/plugins/Weather/src/weather_update.cpp +++ b/plugins/Weather/src/weather_update.cpp @@ -594,6 +594,7 @@ void CALLBACK timerProc(HWND, UINT, UINT_PTR, DWORD) UpdateAll(TRUE, FALSE); } + // temporary timer for first run // when this is run, it kill the old startup timer and create the permenant one above void CALLBACK timerProc2(HWND, UINT, UINT_PTR, DWORD) @@ -606,5 +607,5 @@ void CALLBACK timerProc2(HWND, UINT, UINT_PTR, DWORD) if (opt.StartupUpdate && opt.NoProtoCondition) UpdateAll(FALSE, FALSE); - timerId = SetTimer(NULL, 0, ((int)opt.UpdateTime) * 60000, (TIMERPROC)timerProc); + timerId = SetTimer(NULL, 0, ((int)opt.UpdateTime) * 60000, timerProc); } -- cgit v1.2.3