From b766ebf1a1091dcc2859a92da300c44e0e432a84 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 20 Jun 2012 06:52:26 +0000 Subject: - avatars fix for Weather - code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@495 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Weather/weather.cpp | 2 +- protocols/Weather/weather_conv.cpp | 15 +++--- protocols/Weather/weather_data.cpp | 8 +-- protocols/Weather/weather_http.cpp | 20 ++++---- protocols/Weather/weather_popup.cpp | 4 +- protocols/Weather/weather_svcs.cpp | 90 +++++++++++++--------------------- protocols/Weather/weather_update.cpp | 6 +-- protocols/Weather/weather_userinfo.cpp | 14 +++--- 8 files changed, 66 insertions(+), 93 deletions(-) diff --git a/protocols/Weather/weather.cpp b/protocols/Weather/weather.cpp index 08a8903496..ad51c93a01 100644 --- a/protocols/Weather/weather.cpp +++ b/protocols/Weather/weather.cpp @@ -182,7 +182,7 @@ void InitVar() UpdateListHead = NULL; // other settings - timerId=0; + timerId = 0; opt.DefStn = NULL; ModuleLoaded = FALSE; } diff --git a/protocols/Weather/weather_conv.cpp b/protocols/Weather/weather_conv.cpp index 8cab451181..ff5e37cb58 100644 --- a/protocols/Weather/weather_conv.cpp +++ b/protocols/Weather/weather_conv.cpp @@ -37,7 +37,7 @@ BOOL is_number(TCHAR *s) // don't care anything that comes after it while(*s != '\0') { - if (*s >= '0' && *s <='9') return TRUE; + if (*s >= '0' && *s <= '9') return TRUE; else if (*s == ' '); else if (*s != '+' && *s != '-') return FALSE; else if ((*s == '+' || *s == '-') && !tag) tag = TRUE; @@ -417,7 +417,7 @@ void CaseConv(TCHAR *str) CharLowerBuff(str, (DWORD)_tcslen(str)); for(pstr = str; *pstr; pstr++) { - if (*pstr==' ' || *pstr=='-') + if (*pstr == ' ' || *pstr == '-') nextUp = TRUE; else { TCHAR ch = *(TCHAR*)pstr; @@ -452,13 +452,12 @@ void TrimString(WCHAR *str) // convert \t to tab and \n to linefeed void ConvertBackslashes(char *str) { - char *pstr; - for ( pstr=str; *pstr; pstr = CharNextA(pstr)) { - if (*pstr=='\\') { + for (char *pstr=str; *pstr; pstr = CharNextA(pstr)) { + if (*pstr == '\\') { switch(pstr[1]) { - case 'n': *pstr='\n'; break; - case 't': *pstr='\t'; break; - default: *pstr=pstr[1]; break; + case 'n': *pstr = '\n'; break; + case 't': *pstr = '\t'; break; + default: *pstr = pstr[1]; break; } memmove(pstr+1, pstr+2, strlen(pstr+2)+1); } } } diff --git a/protocols/Weather/weather_data.cpp b/protocols/Weather/weather_data.cpp index 85c87bb972..a0e78f1f93 100644 --- a/protocols/Weather/weather_data.cpp +++ b/protocols/Weather/weather_data.cpp @@ -429,12 +429,12 @@ void DBDataManage(HANDLE hContact, WORD Mode, WPARAM wParam, LPARAM lParam) WCOUNTER wc; wc.current = 0; - dbces.lParam=(LPARAM)&wc; - dbces.pfnEnumProc=GetWeatherDataFromDB; - dbces.szModule=WEATHERCONDITION; + dbces.lParam = (LPARAM)&wc; + dbces.pfnEnumProc = GetWeatherDataFromDB; + dbces.szModule = WEATHERCONDITION; // get all the settings and stored them in a temporary list - if (CallService(MS_DB_CONTACT_ENUMSETTINGS,(WPARAM)hContact,(LPARAM)&dbces)==-1) + if (CallService(MS_DB_CONTACT_ENUMSETTINGS,(WPARAM)hContact,(LPARAM)&dbces) == -1) wc.current--; // begin deleting settings diff --git a/protocols/Weather/weather_http.cpp b/protocols/Weather/weather_http.cpp index 69a54de31a..2a3796de66 100644 --- a/protocols/Weather/weather_http.cpp +++ b/protocols/Weather/weather_http.cpp @@ -49,7 +49,7 @@ int findHeader(NETLIBHTTPREQUEST *nlhrReply, char *hdr) int InternetDownloadFile (char *szUrl, char* cookie, TCHAR** szData) { int result = 0xBADBAD; - char* szRedirUrl = NULL; + char* szRedirUrl = NULL; NETLIBHTTPREQUEST nlhr = {0}, *nlhrReply; NETLIBHTTPHEADER headers[6]; @@ -66,17 +66,17 @@ int InternetDownloadFile (char *szUrl, char* cookie, TCHAR** szData) // change the header so the plugin is pretended to be IE 6 + WinXP nlhr.headersCount = 5; nlhr.headers = headers; - nlhr.headers[0].szName = "User-Agent"; + nlhr.headers[0].szName = "User-Agent"; nlhr.headers[0].szValue = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"; - nlhr.headers[1].szName = "Cache-Control"; + nlhr.headers[1].szName = "Cache-Control"; nlhr.headers[1].szValue = "no-cache"; - nlhr.headers[2].szName = "Pragma"; + nlhr.headers[2].szName = "Pragma"; nlhr.headers[2].szValue = "no-cache"; - nlhr.headers[3].szName = "Connection"; + nlhr.headers[3].szName = "Connection"; nlhr.headers[3].szValue = "close"; - nlhr.headers[4].szName = "Cookie"; + nlhr.headers[4].szName = "Cookie"; nlhr.headers[4].szValue = cookie; -// nlhr.headers[5].szName = "If-Modified-Since"; +// nlhr.headers[5].szName = "If-Modified-Since"; // nlhr.headers[5].szValue = "Tue, 24 Feb 2009 03:44:23 GMT"; if (cookie == NULL || cookie[0] == 0) --nlhr.headersCount; @@ -105,9 +105,9 @@ int InternetDownloadFile (char *szUrl, char* cookie, TCHAR** szData) else { char* method, tmp; end = strchr(beg, '>'); - tmp = *end; *end = 0; + tmp = *end; *end = 0; - method = strstr(beg, "http-equiv=\""); + method = strstr(beg, "http-equiv=\""); if (method && _strnicmp(method+12, "Content-Type", 12) == 0 && strstr(method, "utf-8")) { bIsUtf = true; break; @@ -193,7 +193,7 @@ void NetlibInit(void) nlu.flags = NUF_OUTGOING|NUF_HTTPCONNS|NUF_NOHTTPSOPTION; nlu.szSettingsModule = WEATHERPROTONAME; nlu.szDescriptiveName = Translate("Weather HTTP connections"); - hNetlibUser=(HANDLE)CallService(MS_NETLIB_REGISTERUSER,0,(LPARAM)&nlu); + hNetlibUser = (HANDLE)CallService(MS_NETLIB_REGISTERUSER,0,(LPARAM)&nlu); } void NetlibHttpDisconnect(void) diff --git a/protocols/Weather/weather_popup.cpp b/protocols/Weather/weather_popup.cpp index 5a912714c9..1b440364d0 100644 --- a/protocols/Weather/weather_popup.cpp +++ b/protocols/Weather/weather_popup.cpp @@ -180,7 +180,7 @@ LRESULT CALLBACK PopupWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam break; case IDM_M7: // display contact menu - hMenu=(HMENU)CallService(MS_CLIST_MENUBUILDCONTACT,wParam,0); + hMenu = (HMENU)CallService(MS_CLIST_MENUBUILDCONTACT,wParam,0); GetCursorPos(&pt); hPopupContact = (HANDLE)wParam; TrackPopupMenu(hMenu,TPM_LEFTALIGN,pt.x,pt.y,0,hWnd,NULL); @@ -307,7 +307,7 @@ INT_PTR CALLBACK DlgPopUpOpts(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam) case WM_COMMAND: // enable the "apply" button - if (HIWORD(wParam)==BN_CLICKED && GetFocus()==(HWND)lParam) + if (HIWORD(wParam) == BN_CLICKED && GetFocus() == (HWND)lParam) SendMessage(GetParent(hdlg),PSM_CHANGED,0,0); if (!((LOWORD(wParam) == IDC_UPDATE || LOWORD(wParam) == IDC_DEGREE) && (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()))) diff --git a/protocols/Weather/weather_svcs.cpp b/protocols/Weather/weather_svcs.cpp index 30559334b1..f3b5de472e 100644 --- a/protocols/Weather/weather_svcs.cpp +++ b/protocols/Weather/weather_svcs.cpp @@ -125,35 +125,12 @@ INT_PTR WeatherGetInfo(WPARAM wParam,LPARAM lParam) return 0; } +// avatars +static const TCHAR *statusStr[] = { _T("Light"), _T("Fog"), _T("SShower"), _T("Snow"), _T("RShower"), _T("Rain"), _T("PCloudy"), _T("Cloudy"), _T("Sunny"), _T("NA") }; +static const WORD statusValue[] = { LIGHT, FOG, SSHOWER, SNOW, RSHOWER, RAIN, PCLOUDY, CLOUDY, SUNNY, NA }; INT_PTR WeatherGetAvatarInfo(WPARAM wParam, LPARAM lParam) { - static const char *statusStr[] = { - "Light", - "Fog", - "SShower", - "Snow", - "RShower", - "Rain", - "PCloudy", - "Cloudy", - "Sunny", - "NA" - }; - - static const WORD statusValue[] = { - LIGHT, - FOG, - SSHOWER, - SNOW, - RSHOWER, - RAIN, - PCLOUDY, - CLOUDY, - SUNNY, - NA - }; - TCHAR szSearchPath[MAX_PATH], *chop; WORD status; unsigned i; @@ -170,35 +147,33 @@ INT_PTR WeatherGetAvatarInfo(WPARAM wParam, LPARAM lParam) { if (statusValue[i] == status) break; - } - if (i >= 10) return GAIR_NOAVATAR; + + if (i >= 10) + return GAIR_NOAVATAR; ai->format = PA_FORMAT_PNG; wsprintf(ai->filename, _T("%s\\Plugins\\Weather\\%s.png"), szSearchPath, statusStr[i]); - if (_taccess(ai->filename, 4) == 0) return GAIR_SUCCESS; + if ( _taccess(ai->filename, 4) == 0) + return GAIR_SUCCESS; ai->format = PA_FORMAT_GIF; wsprintf(ai->filename, _T("%s\\Plugins\\Weather\\%s.gif"), szSearchPath, statusStr[i]); - if (_taccess(ai->filename, 4) == 0) return GAIR_SUCCESS; + if ( _taccess(ai->filename, 4) == 0) + return GAIR_SUCCESS; ai->format = PA_FORMAT_UNKNOWN; ai->filename[0] = 0; - return GAIR_NOAVATAR; + return GAIR_NOAVATAR; } void AvatarDownloaded(HANDLE hContact) { - int haveAvatar; PROTO_AVATAR_INFORMATIONT AI = {0}; AI.cbSize = sizeof(AI); AI.hContact = hContact; -// ProtoBroadcastAck(WEATHERPROTONAME, hContact, ACKTYPE_AVATAR, ACKRESULT_STATUS, NULL, 0); - - haveAvatar = WeatherGetAvatarInfo(GAIF_FORCE, (LPARAM)&AI) == GAIR_SUCCESS; - - if (haveAvatar) + if (WeatherGetAvatarInfo(GAIF_FORCE, (LPARAM)&AI) == GAIR_SUCCESS) ProtoBroadcastAck(WEATHERPROTONAME, hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, &AI, 0); else ProtoBroadcastAck(WEATHERPROTONAME, hContact, ACKTYPE_AVATAR, ACKRESULT_STATUS, NULL, 0); @@ -207,8 +182,9 @@ void AvatarDownloaded(HANDLE hContact) static void __cdecl WeatherGetAwayMsgThread(HANDLE hContact) { - DBVARIANT dbv; Sleep(100); + + DBVARIANT dbv; if ( !DBGetContactSettingTString(hContact, "CList", "StatusMsg", &dbv)) { ProtoBroadcastAck(WEATHERPROTONAME, hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, (HANDLE)1, (LPARAM)dbv.ptszVal); DBFreeVariant( &dbv ); @@ -350,51 +326,51 @@ void AddMenuItems(void) // contact menu hService[15] = CreateServiceFunction(MS_WEATHER_UPDATE, UpdateSingleStation); - mi.position=-0x7FFFFFFA; + mi.position = -0x7FFFFFFA; mi.icolibItem = GetIconHandle("update"); - mi.pszName="Update Weather"; + mi.pszName = "Update Weather"; mi.pszService = MS_WEATHER_UPDATE; Menu_AddContactMenuItem(&mi); hService[16] = CreateServiceFunction(MS_WEATHER_REFRESH, UpdateSingleRemove); - mi.position=-0x7FFFFFF9; + mi.position = -0x7FFFFFF9; mi.icolibItem = GetIconHandle("update2"); - mi.pszName="Remove Old Data then Update"; + mi.pszName = "Remove Old Data then Update"; mi.pszService = MS_WEATHER_REFRESH; Menu_AddContactMenuItem(&mi); hService[17] = CreateServiceFunction(MS_WEATHER_BRIEF, BriefInfoSvc); - mi.position=-0x7FFFFFF8; + mi.position = -0x7FFFFFF8; mi.icolibItem = GetIconHandle("brief"); - mi.pszName="Brief Information"; + mi.pszName = "Brief Information"; mi.pszService = MS_WEATHER_BRIEF; Menu_AddContactMenuItem(&mi); hService[18] = CreateServiceFunction(MS_WEATHER_COMPLETE, LoadForecast); - mi.position=-0x7FFFFFF7; + mi.position = -0x7FFFFFF7; mi.icolibItem = GetIconHandle("read"); - mi.pszName="Read Complete Forecast"; + mi.pszName = "Read Complete Forecast"; mi.pszService = MS_WEATHER_COMPLETE; Menu_AddContactMenuItem(&mi); hService[19] = CreateServiceFunction(MS_WEATHER_MAP, WeatherMap); - mi.position=-0x7FFFFFF6; + mi.position = -0x7FFFFFF6; mi.icolibItem = GetIconHandle("map"); - mi.pszName="Weather Map"; + mi.pszName = "Weather Map"; mi.pszService = MS_WEATHER_MAP; Menu_AddContactMenuItem(&mi); hService[20] = CreateServiceFunction(MS_WEATHER_LOG, ViewLog); - mi.position=-0x7FFFFFF5; + mi.position = -0x7FFFFFF5; mi.icolibItem = GetIconHandle("log"); - mi.pszName="View Log"; + mi.pszName = "View Log"; mi.pszService = MS_WEATHER_LOG; Menu_AddContactMenuItem(&mi); hService[21] = CreateServiceFunction(MS_WEATHER_EDIT, EditSettings); - mi.position=-0x7FFFFFF4; + mi.position = -0x7FFFFFF4; mi.icolibItem = GetIconHandle("edit"); - mi.pszName="Edit Settings"; + mi.pszName = "Edit Settings"; mi.pszService = MS_WEATHER_EDIT; Menu_AddContactMenuItem(&mi); @@ -405,22 +381,22 @@ void AddMenuItems(void) hService[22] = CreateServiceFunction(MS_WEATHER_ENABLED, EnableDisableCmd); mi.pszName = "Enable/Disable Weather Update"; mi.icolibItem = GetIconHandle("main"); - mi.position=10100001; + mi.position = 10100001; mi.pszService = MS_WEATHER_ENABLED; hEnableDisableMenu = Menu_AddMainMenuItem(&mi); UpdateMenu(opt.AutoUpdate); hService[23] = CreateServiceFunction(MS_WEATHER_UPDATEALL, UpdateAllInfo); - mi.position=20100001; + mi.position = 20100001; mi.icolibItem = GetIconHandle("update"); - mi.pszName="Update All Weather"; + mi.pszName = "Update All Weather"; mi.pszService = MS_WEATHER_UPDATEALL; Menu_AddMainMenuItem(&mi); hService[24] = CreateServiceFunction(MS_WEATHER_REFRESHALL, UpdateAllRemove); - mi.position=20100002; + mi.position = 20100002; mi.icolibItem = GetIconHandle("update2"); - mi.pszName="Remove Old Data then Update All"; + mi.pszName = "Remove Old Data then Update All"; mi.pszService = MS_WEATHER_REFRESHALL; Menu_AddMainMenuItem(&mi); diff --git a/protocols/Weather/weather_update.cpp b/protocols/Weather/weather_update.cpp index cf3e61826a..f114b80acc 100644 --- a/protocols/Weather/weather_update.cpp +++ b/protocols/Weather/weather_update.cpp @@ -293,7 +293,7 @@ void DestroyUpdateList(void) void UpdateAll(BOOL AutoUpdate, BOOL RemoveData) { // add all weather contact to the update queue list - HANDLE hContact= (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); + HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); while (hContact != NULL) { if (IsMyContact(hContact)) @@ -503,14 +503,14 @@ int GetWeatherData(HANDLE hContact) hasvar = TRUE; if ( !DBGetData(hContact, _T2A(str2), &dbv)) { _tcsncat(DataValue, dbv.ptszVal, SIZEOF(DataValue) - _tcslen(DataValue)); - DataValue[SIZEOF(DataValue)-1]=0; + DataValue[SIZEOF(DataValue)-1] = 0; DBFreeVariant(&dbv); } break; case'\"': // constant, add it to the result string _tcsncat(DataValue, TranslateTS(str2), SIZEOF(DataValue) - _tcslen(DataValue)); - DataValue[SIZEOF(DataValue)-1]=0; + DataValue[SIZEOF(DataValue)-1] = 0; break; } diff --git a/protocols/Weather/weather_userinfo.cpp b/protocols/Weather/weather_userinfo.cpp index 066b004062..055fdb9fed 100644 --- a/protocols/Weather/weather_userinfo.cpp +++ b/protocols/Weather/weather_userinfo.cpp @@ -68,9 +68,8 @@ INT_PTR CALLBACK DlgProcUIPage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa { WEATHERINFO w; TCHAR str[MAX_TEXT_SIZE]; - HANDLE hContact; - hContact = (HANDLE)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + HANDLE hContact = (HANDLE)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); @@ -88,11 +87,11 @@ INT_PTR CALLBACK DlgProcUIPage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa { // bold and enlarge the current condition LOGFONT lf; - HFONT hNormalFont=(HFONT)SendDlgItemMessage(hwndDlg,IDC_INFO2,WM_GETFONT,0,0); + HFONT hNormalFont = (HFONT)SendDlgItemMessage(hwndDlg,IDC_INFO2,WM_GETFONT,0,0); GetObject(hNormalFont,sizeof(lf),&lf); - lf.lfWeight=FW_BOLD; - lf.lfWidth=7; - lf.lfHeight=15; + lf.lfWeight = FW_BOLD; + lf.lfWidth = 7; + lf.lfHeight = 15; SendDlgItemMessage(hwndDlg, IDC_INFO2, WM_SETFONT, (WPARAM)CreateFontIndirect(&lf), 0); } // set the text for displaying other current weather conditions data @@ -119,8 +118,7 @@ INT_PTR CALLBACK DlgProcUIPage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa break; case WM_COMMAND: - switch(LOWORD(wParam)) - { + switch(LOWORD(wParam)) { case IDC_MOREDETAIL: { HWND hMoreDataDlg; -- cgit v1.2.3