diff options
author | George Hazan <george.hazan@gmail.com> | 2015-08-26 09:14:05 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2015-08-26 09:14:05 +0000 |
commit | 6a78b8c34efc8856acab62e22c61a0883311170c (patch) | |
tree | 44fd56e7d52f7329f74f2116780aa3d023fb0ecd | |
parent | 0c4b5818d8d705cd8361ad36bba6797d1daaf30d (diff) |
- warnings' fixes;
- code cleaning
git-svn-id: http://svn.miranda-ng.org/main/trunk@15032 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | plugins/TabSRMM/src/chat/log.cpp | 6 | ||||
-rw-r--r-- | plugins/TipperYM/src/message_pump.cpp | 4 | ||||
-rw-r--r-- | plugins/TipperYM/src/popwin.cpp | 76 | ||||
-rw-r--r-- | plugins/TipperYM/src/subst.cpp | 173 | ||||
-rw-r--r-- | plugins/Utils/mir_buffer.h | 26 | ||||
-rw-r--r-- | src/core/stduserinfo/src/stdinfo.cpp | 205 |
6 files changed, 214 insertions, 276 deletions
diff --git a/plugins/TabSRMM/src/chat/log.cpp b/plugins/TabSRMM/src/chat/log.cpp index 9e2a5c573e..19e37c2676 100644 --- a/plugins/TabSRMM/src/chat/log.cpp +++ b/plugins/TabSRMM/src/chat/log.cpp @@ -989,9 +989,9 @@ void Log_StreamInEvent(HWND hwndDlg, LOGINFO* lin, SESSION_INFO *si, bool bRedra fi.chrg.cpMin = 0;
fi.chrg.cpMax = -1;
if (SendMessage(hwndRich, EM_FINDTEXTEX, FR_DOWN, (LPARAM)&fi) != 0) {
- CHARRANGE sel;
- sel.cpMin = 0;
- sel.cpMax = 20;
+ CHARRANGE rng;
+ rng.cpMin = 0;
+ rng.cpMax = 20;
SendMessage(hwndRich, EM_SETSEL, 0, fi.chrgText.cpMax + 1);
SendMessage(hwndRich, EM_REPLACESEL, TRUE, (LPARAM)_T(""));
}
diff --git a/plugins/TipperYM/src/message_pump.cpp b/plugins/TipperYM/src/message_pump.cpp index fa9f32515d..949d5d9603 100644 --- a/plugins/TipperYM/src/message_pump.cpp +++ b/plugins/TipperYM/src/message_pump.cpp @@ -48,7 +48,7 @@ bool NeedWaitForContent(CLCINFOTIPEX *clcitex) bool bNeedWait = false;
if (opt.bWaitForContent && IsContactTooltip(clcitex))
{
- MCONTACT hContact = (MCONTACT) clcitex->hItem;
+ MCONTACT hContact = (DWORD_PTR)clcitex->hItem;
char *szProto = GetContactProto(hContact);
if (!szProto) return false;
@@ -157,7 +157,7 @@ unsigned int CALLBACK MessagePumpThread(void*) }
if (swzMsg) {
- db_set_ts((MCONTACT)clcitex->hItem, MODULE, "TempStatusMsg", swzMsg);
+ db_set_ts((DWORD_PTR)clcitex->hItem, MODULE, "TempStatusMsg", swzMsg);
mir_free(swzMsg);
}
diff --git a/plugins/TipperYM/src/popwin.cpp b/plugins/TipperYM/src/popwin.cpp index 15b6f6f7f9..8907f068b1 100644 --- a/plugins/TipperYM/src/popwin.cpp +++ b/plugins/TipperYM/src/popwin.cpp @@ -37,10 +37,11 @@ __inline void AddRow(PopupWindowData *pwd, TCHAR *swzLabel, TCHAR *swzValue, cha LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { + POINT pt; RECT rc; PopupWindowData *pwd = (PopupWindowData *)GetWindowLongPtr(hwnd, GWLP_USERDATA); - switch(uMsg) { + switch (uMsg) { case WM_CREATE: { CREATESTRUCT *cs = (CREATESTRUCT *)lParam; @@ -126,11 +127,10 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa if (wStatus >= ID_STATUS_ONLINE && wStatus <= ID_STATUS_OUTTOLUNCH) { // status message - TCHAR *swzText = GetProtoStatusMessage(pwd->clcit.szProto, wStatus); - if (swzText) { - StripBBCodesInPlace(swzText); - AddRow(pwd, TranslateT("Status message:"), swzText, pwd->clcit.szProto, true, true, true); - mir_free(swzText); + ptrT ptszStatus(GetProtoStatusMessage(pwd->clcit.szProto, wStatus)); + if (ptszStatus) { + StripBBCodesInPlace(ptszStatus); + AddRow(pwd, TranslateT("Status message:"), ptszStatus, pwd->clcit.szProto, true, true, true); } // jabber mood or icq xstatus @@ -139,11 +139,10 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa StripBBCodesInPlace(swzAdvTitle); AddRow(pwd, TranslateT("Mood:"), swzAdvTitle, pwd->clcit.szProto, true, false, true); - TCHAR *swzAdvText = GetJabberAdvStatusText(pwd->clcit.szProto, "mood", "text"); + ptrT swzAdvText(GetJabberAdvStatusText(pwd->clcit.szProto, "mood", "text")); if (swzAdvText) { StripBBCodesInPlace(swzAdvText); AddRow(pwd, _T(""), swzAdvText, pwd->clcit.szProto, true, true, false); - mir_free(swzAdvText); } } else { @@ -156,11 +155,10 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa } // xstatus message - TCHAR *swzAdvText = GetProtoExtraStatusMessage(pwd->clcit.szProto); + ptrT swzAdvText(GetProtoExtraStatusMessage(pwd->clcit.szProto)); if (swzAdvText) { StripBBCodesInPlace(swzAdvText); AddRow(pwd, _T(""), swzAdvText, pwd->clcit.szProto, true, true, false); - mir_free(swzAdvText); } } } @@ -175,26 +173,23 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa } // jabber activity - TCHAR *swzActTitle = GetJabberAdvStatusText(pwd->clcit.szProto, "activity", "title"); + ptrT swzActTitle(GetJabberAdvStatusText(pwd->clcit.szProto, "activity", "title")); if (swzActTitle) { StripBBCodesInPlace(swzActTitle); AddRow(pwd, TranslateT("Activity:"), swzActTitle, pwd->clcit.szProto, true, false, true); - mir_free(swzActTitle); } - TCHAR *swzActText = GetJabberAdvStatusText(pwd->clcit.szProto, "activity", "text"); + ptrT swzActText(GetJabberAdvStatusText(pwd->clcit.szProto, "activity", "text")); if (swzActText) { StripBBCodesInPlace(swzActText); AddRow(pwd, _T(""), swzActText, pwd->clcit.szProto, true, true, false); - mir_free(swzActText); } // listening to - TCHAR *swzListening = GetListeningTo(pwd->clcit.szProto); + ptrT swzListening(GetListeningTo(pwd->clcit.szProto)); if (swzListening) { StripBBCodesInPlace(swzListening); AddRow(pwd, TranslateT("Listening to:"), swzListening, NULL, false, true, true); - mir_free(swzListening); } } } @@ -304,22 +299,20 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa pwd->bIsTextTip = false; pwd->iIndent = opt.iTextIndent; pwd->iSidebarWidth = opt.iSidebarWidth; - pwd->hContact = (MCONTACT)pwd->clcit.hItem; + pwd->hContact = (DWORD_PTR)pwd->clcit.hItem; pwd->iIconIndex = (int)CallService(MS_CLIST_GETCONTACTICON, pwd->hContact, 0); // don't use stored status message if (!opt.bWaitForContent) db_unset(pwd->hContact, MODULE, "TempStatusMsg"); - TCHAR *swzNick = pcli->pfnGetContactDisplayName(pwd->hContact, 0); - _tcsncpy(pwd->swzTitle, swzNick, TITLE_TEXT_LEN); + _tcsncpy_s(pwd->swzTitle, pcli->pfnGetContactDisplayName(pwd->hContact, 0), _TRUNCATE); char *szProto = GetContactProto(pwd->hContact); pwd->spiTitle = Smileys_PreParse(pwd->swzTitle, -1, szProto); // get extra icons - DBVARIANT dbv = { 0 }; - int i = 0; + int i; if (szProto) { // status icon @@ -336,10 +329,13 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa if (iXstatus) { char szIconProto[64]; if (mir_strcmp(szProto, META_PROTO) != 0) - strncpy(szIconProto, szProto, sizeof(szIconProto) - 1); - else if (!db_get_s(pwd->hContact, szProto, "XStatusProto", &dbv)) { - strncpy(szIconProto, dbv.pszVal, sizeof(szIconProto) - 1); - db_free(&dbv); + strncpy_s(szIconProto, szProto, _TRUNCATE); + else { + ptrA szXProto(db_get_sa(pwd->hContact, szProto, "XStatusProto")); + if (szXProto != NULL) + strncpy_s(szIconProto, szXProto, _TRUNCATE); + else + szIconProto[0] = 0; } pwd->extraIcons[i].hIcon = (HICON)CallProtoService(szIconProto, PS_GETCUSTOMSTATUSICON, (WPARAM)iXstatus, LR_SHARED); @@ -386,10 +382,10 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa if (pwd->bIsIconVisible[5]) { for (i = 0; opt.exIconsOrder[i] != 5; i++); if (ServiceExists(MS_FP_GETCLIENTICONT)) { - if (!db_get_ts(pwd->hContact, szProto, "MirVer", &dbv)) { - pwd->extraIcons[i].hIcon = Finger_GetClientIcon(dbv.ptszVal, 0); + ptrT tszVersion(db_get_tsa(pwd->hContact, szProto, "MirVer")); + if (tszVersion != NULL) { + pwd->extraIcons[i].hIcon = Finger_GetClientIcon(tszVersion, 0); pwd->extraIcons[i].bDestroy = true; - db_free(&dbv); } } } @@ -425,7 +421,7 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa // since tipper win is topmost, this should put it at top of topmost windows SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); - } + } return 0; case WM_ERASEBKGND: @@ -487,7 +483,7 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa rcAvatar.right = rcAvatar.left + pwd->iRealAvatarWidth; r2.left += pwd->iRealAvatarWidth + (opt.iOuterAvatarPadding + opt.iInnerAvatarPadding - opt.iPadding); // padding re-added for text } - else if (opt.avatarLayout == PAV_RIGHT) { + else { rcAvatar.right = r.right - opt.iOuterAvatarPadding; rcAvatar.left = rcAvatar.right - pwd->iRealAvatarWidth; r2.right -= pwd->iRealAvatarWidth + (opt.iOuterAvatarPadding + opt.iInnerAvatarPadding - opt.iPadding); @@ -786,7 +782,6 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa } } - POINT pt; GetCursorPos(&pt); SetForegroundWindow(hwnd); int iSelItem = TrackPopupMenu(hMenu, TPM_RETURNCMD, pt.x, pt.y, 0, hwnd, 0); @@ -953,16 +948,14 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa SendMessage(hwnd, PUM_UPDATERGN, 1, 0); break; case ID_TIMER_CHECKMOUSE: - { - // workaround for tips that just won't go away - POINT pt; - - GetCursorPos(&pt); - // mouse has moved beyond tollerance - if (abs(pt.x - pwd->ptCursorStartPos.x) > opt.iMouseTollerance || abs(pt.y - pwd->ptCursorStartPos.y) > opt.iMouseTollerance) - PostMPMessage(MUM_DELETEPOPUP, 0, 0); - } - break; + { + // workaround for tips that just won't go away + GetCursorPos(&pt); + // mouse has moved beyond tollerance + if (abs(pt.x - pwd->ptCursorStartPos.x) > opt.iMouseTollerance || abs(pt.y - pwd->ptCursorStartPos.y) > opt.iMouseTollerance) + PostMPMessage(MUM_DELETEPOPUP, 0, 0); + } + break; case ID_TIMER_TRAYTIP: KillTimer(hwnd, ID_TIMER_TRAYTIP); SendMessage(hwnd, PUM_EXPANDTRAYTIP, 0, 0); @@ -1454,7 +1447,6 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa Smileys_FreeParse(pwd->rows[i].spi); } - mir_free(pwd->rows); pwd->rows = NULL; pwd->iRowCount = 0; diff --git a/plugins/TipperYM/src/subst.cpp b/plugins/TipperYM/src/subst.cpp index f149ba63e5..10335265d9 100644 --- a/plugins/TipperYM/src/subst.cpp +++ b/plugins/TipperYM/src/subst.cpp @@ -76,44 +76,44 @@ bool CheckContactType(MCONTACT hContact, const DISPLAYITEM &di) return false; } -void StripBBCodesInPlace(TCHAR *swzText) +void StripBBCodesInPlace(TCHAR *ptszText) { if (!db_get_b(0, MODULE, "StripBBCodes", 1)) return; - if (swzText == 0) + if (ptszText == 0) return; size_t iRead = 0, iWrite = 0; - size_t iLen = mir_tstrlen(swzText); + size_t iLen = mir_tstrlen(ptszText); while(iRead <= iLen) { // copy terminating null too - while (iRead <= iLen && swzText[iRead] != '[') { - if (swzText[iRead] != swzText[iWrite]) swzText[iWrite] = swzText[iRead]; + while (iRead <= iLen && ptszText[iRead] != '[') { + if (ptszText[iRead] != ptszText[iWrite]) ptszText[iWrite] = ptszText[iRead]; iRead++; iWrite++; } if (iRead > iLen) break; - if (iLen - iRead >= 3 && (_tcsnicmp(swzText + iRead, _T("[b]"), 3) == 0 || _tcsnicmp(swzText + iRead, _T("[i]"), 3) == 0)) + if (iLen - iRead >= 3 && (_tcsnicmp(ptszText + iRead, _T("[b]"), 3) == 0 || _tcsnicmp(ptszText + iRead, _T("[i]"), 3) == 0)) iRead += 3; - else if (iLen - iRead >= 4 && (_tcsnicmp(swzText + iRead, _T("[/b]"), 4) == 0 || _tcsnicmp(swzText + iRead, _T("[/i]"), 4) == 0)) + else if (iLen - iRead >= 4 && (_tcsnicmp(ptszText + iRead, _T("[/b]"), 4) == 0 || _tcsnicmp(ptszText + iRead, _T("[/i]"), 4) == 0)) iRead += 4; - else if (iLen - iRead >= 6 && (_tcsnicmp(swzText + iRead, _T("[color"), 6) == 0)) { - while (iRead < iLen && swzText[iRead] != ']') iRead++; + else if (iLen - iRead >= 6 && (_tcsnicmp(ptszText + iRead, _T("[color"), 6) == 0)) { + while (iRead < iLen && ptszText[iRead] != ']') iRead++; iRead++;// skip the ']' } - else if (iLen - iRead >= 8 && (_tcsnicmp(swzText + iRead, _T("[/color]"), 8) == 0)) + else if (iLen - iRead >= 8 && (_tcsnicmp(ptszText + iRead, _T("[/color]"), 8) == 0)) iRead += 8; - else if (iLen - iRead >= 5 && (_tcsnicmp(swzText + iRead, _T("[size"), 5) == 0)) { - while (iRead < iLen && swzText[iRead] != ']') iRead++; + else if (iLen - iRead >= 5 && (_tcsnicmp(ptszText + iRead, _T("[size"), 5) == 0)) { + while (iRead < iLen && ptszText[iRead] != ']') iRead++; iRead++;// skip the ']' } - else if (iLen - iRead >= 7 && (_tcsnicmp(swzText + iRead, _T("[/size]"), 7) == 0)) + else if (iLen - iRead >= 7 && (_tcsnicmp(ptszText + iRead, _T("[/size]"), 7) == 0)) iRead += 7; else { - if (swzText[iRead] != swzText[iWrite]) swzText[iWrite] = swzText[iRead]; + if (ptszText[iRead] != ptszText[iWrite]) ptszText[iWrite] = ptszText[iRead]; iRead++; iWrite++; } } @@ -162,7 +162,7 @@ bool UidName(char *szProto, TCHAR *buff, int bufflen) return false; } -TCHAR *GetLastMessageText(MCONTACT hContact, bool received) +TCHAR* GetLastMessageText(MCONTACT hContact, bool received) { for (MEVENT hDbEvent = db_event_last(hContact); hDbEvent; hDbEvent = db_event_prev(hContact, hDbEvent)) { DBEVENTINFO dbei = { sizeof(dbei) }; @@ -673,17 +673,17 @@ bool GetValueText(MCONTACT hContact, const DISPLAYITEM &di, TCHAR *buff, size_t return ApplySubst(hContact, di.swzValue, di.bParseTipperVarsFirst, buff, bufflen); } -void TruncateString(TCHAR *swzText) +void TruncateString(TCHAR *ptszText) { - if (swzText && opt.iLimitCharCount > 3) { - if ((int)mir_tstrlen(swzText) > opt.iLimitCharCount) { - swzText[opt.iLimitCharCount - 3] = 0; - mir_tstrcat(swzText, _T("...")); + if (ptszText && opt.iLimitCharCount > 3) { + if ((int)mir_tstrlen(ptszText) > opt.iLimitCharCount) { + ptszText[opt.iLimitCharCount - 3] = 0; + mir_tstrcat(ptszText, _T("...")); } } } -TCHAR *GetProtoStatusMessage(char *szProto, WORD wStatus) +TCHAR* GetProtoStatusMessage(char *szProto, WORD wStatus) { if (!szProto || wStatus == ID_STATUS_OFFLINE) return NULL; @@ -693,150 +693,115 @@ TCHAR *GetProtoStatusMessage(char *szProto, WORD wStatus) if (!(flags & Proto_Status2Flag(wStatus))) return NULL; - TCHAR *swzText = (TCHAR *)CallProtoService(szProto, PS_GETMYAWAYMSG, 0, SGMA_TCHAR); - if ((INT_PTR)swzText == CALLSERVICE_NOTFOUND) - swzText = (TCHAR *)CallService(MS_AWAYMSG_GETSTATUSMSGT, wStatus, (LPARAM)szProto); + TCHAR *ptszText = (TCHAR *)CallProtoService(szProto, PS_GETMYAWAYMSG, 0, SGMA_TCHAR); + if ((INT_PTR)ptszText == CALLSERVICE_NOTFOUND) + ptszText = (TCHAR *)CallService(MS_AWAYMSG_GETSTATUSMSGT, wStatus, (LPARAM)szProto); - else if (swzText == NULL) { + else if (ptszText == NULL) { // try to use service without SGMA_TCHAR char *tmpMsg = (char *)CallProtoService(szProto, PS_GETMYAWAYMSG, 0, 0); if (tmpMsg && (INT_PTR)tmpMsg != CALLSERVICE_NOTFOUND) { - swzText = mir_a2t(tmpMsg); + ptszText = mir_a2t(tmpMsg); mir_free(tmpMsg); } } - if (swzText && !swzText[0]) { - mir_free(swzText); - swzText = NULL; + if (ptszText && !ptszText[0]) { + mir_free(ptszText); + ptszText = NULL; } - if (swzText && opt.bLimitMsg) - TruncateString(swzText); + if (ptszText && opt.bLimitMsg) + TruncateString(ptszText); - return swzText; + return ptszText; } -TCHAR *GetProtoExtraStatusTitle(char *szProto) +TCHAR* GetProtoExtraStatusTitle(char *szProto) { - DBVARIANT dbv; - TCHAR *swzText = NULL; - if (!szProto) return NULL; - if (!db_get_ts(0, szProto, "XStatusName", &dbv)) { - if (mir_tstrlen(dbv.ptszVal) != 0) - swzText = mir_tstrdup(dbv.ptszVal); - db_free(&dbv); - } - - if (!swzText) { + TCHAR *ptszText = db_get_tsa(0, szProto, "XStatusName"); + if (!ptszText) { TCHAR buff[256]; if (EmptyXStatusToDefaultName(0, szProto, 0, buff, 256)) - swzText = mir_tstrdup(buff); + ptszText = mir_tstrdup(buff); } if (opt.bLimitMsg) - TruncateString(swzText); + TruncateString(ptszText); - return swzText; + return ptszText; } -TCHAR *GetProtoExtraStatusMessage(char *szProto) +TCHAR* GetProtoExtraStatusMessage(char *szProto) { if (!szProto) return NULL; - TCHAR *swzText = NULL; - DBVARIANT dbv; - if (!db_get_ts(0, szProto, "XStatusMsg", &dbv)) { - if (mir_tstrlen(dbv.ptszVal) != 0) - swzText = mir_tstrdup(dbv.ptszVal); - db_free(&dbv); + TCHAR *ptszText = db_get_tsa(0, szProto, "XStatusMsg"); + if (ptszText == NULL) + return NULL; - if (ServiceExists(MS_VARS_FORMATSTRING)) { - MCONTACT hContact = db_find_first(); - char *proto = GetContactProto(hContact); - while (!proto) { - hContact = db_find_next(hContact); - if (hContact) - proto = GetContactProto(hContact); - else { - hContact = NULL; - break; - } + if (ServiceExists(MS_VARS_FORMATSTRING)) { + MCONTACT hContact = db_find_first(); + char *proto = GetContactProto(hContact); + while (!proto) { + hContact = db_find_next(hContact); + if (hContact) + proto = GetContactProto(hContact); + else { + hContact = NULL; + break; } - - TCHAR *tszParsed = variables_parse(swzText, NULL, hContact); - if (tszParsed) - replaceStrT(swzText, tszParsed); } + + TCHAR *tszParsed = variables_parse(ptszText, NULL, hContact); + if (tszParsed) + replaceStrT(ptszText, tszParsed); } if (opt.bLimitMsg) - TruncateString(swzText); + TruncateString(ptszText); - return swzText; + return ptszText; } -TCHAR *GetListeningTo(char *szProto) +TCHAR* GetListeningTo(char *szProto) { - DBVARIANT dbv; - TCHAR *swzText = NULL; - if (!szProto) return NULL; - if (!db_get_ts(0, szProto, "ListeningTo", &dbv)) { - if (mir_tstrlen(dbv.ptszVal) != 0) - swzText = mir_tstrdup(dbv.ptszVal); - db_free(&dbv); - } - + TCHAR *ptszText = db_get_tsa(0, szProto, "ListeningTo"); if (opt.bLimitMsg) - TruncateString(swzText); + TruncateString(ptszText); - return swzText; + return ptszText; } -TCHAR *GetJabberAdvStatusText(char *szProto, const char *szSlot, const char *szValue) +TCHAR* GetJabberAdvStatusText(char *szProto, const char *szSlot, const char *szValue) { - DBVARIANT dbv; - TCHAR *swzText = NULL; - if (!szProto) return NULL; char szSetting[128]; mir_snprintf(szSetting, "%s/%s/%s", szProto, szSlot, szValue); - if (!db_get_ts(0, "AdvStatus", szSetting, &dbv)) { - if (mir_tstrlen(dbv.ptszVal) != 0) - swzText = mir_tstrdup(dbv.ptszVal); - db_free(&dbv); - } - + TCHAR *ptszText = db_get_tsa(0, "AdvStatus", szSetting); if (opt.bLimitMsg) - TruncateString(swzText); + TruncateString(ptszText); - return swzText; + return ptszText; } HICON GetJabberActivityIcon(MCONTACT hContact, char *szProto) { - DBVARIANT dbv; - HICON hIcon = NULL; - if (!szProto) return NULL; char szSetting[128]; mir_snprintf(szSetting, "%s/%s/%s", szProto, "activity", "icon"); - if (!db_get_s(hContact, "AdvStatus", szSetting, &dbv)) { - hIcon = IcoLib_GetIcon(dbv.pszVal); - db_free(&dbv); - } - - return hIcon; -}
\ No newline at end of file + ptrA szIcon(db_get_sa(hContact, "AdvStatus", szSetting)); + return (szIcon != NULL) ? IcoLib_GetIcon(szIcon) : NULL; +} diff --git a/plugins/Utils/mir_buffer.h b/plugins/Utils/mir_buffer.h index c8388bd731..4d5361b8ab 100644 --- a/plugins/Utils/mir_buffer.h +++ b/plugins/Utils/mir_buffer.h @@ -27,67 +27,63 @@ Boston, MA 02111-1307, USA. #include <m_timezones.h>
template<class T>
-static inline size_t __blen(const T *str)
+inline size_t __blen(const T *str)
{
return 0;
}
template<>
-static inline size_t __blen<char>(const char *str)
+inline size_t __blen<char>(const char *str)
{
return mir_strlen(str);
}
template<>
-static inline size_t __blen<wchar_t>(const wchar_t *str)
+inline size_t __blen<wchar_t>(const wchar_t *str)
{
return mir_wstrlen(str);
}
template<class T>
-static inline T * __bTranslate(const T *str)
+inline T * __bTranslate(const T *str)
{
return 0;
}
template<>
-static inline char * __bTranslate<char>(const char *str)
+inline char * __bTranslate<char>(const char *str)
{
return Translate(str);
}
template<>
-static inline wchar_t * __bTranslate<wchar_t>(const wchar_t *str)
+inline wchar_t * __bTranslate<wchar_t>(const wchar_t *str)
{
return TranslateW(str);
}
template<class O, class D>
-static void __bcopy(D *dest, const O *orig, size_t len)
+inline void __bcopy(D *dest, const O *orig, size_t len)
{
}
-template<>
-static void __bcopy(char *dest, const char *orig, size_t len)
+inline void __bcopy(char *dest, const char *orig, size_t len)
{
strncpy(dest, orig, len);
}
-template<>
-static void __bcopy(WCHAR *dest, const WCHAR *orig, size_t len)
+inline void __bcopy(WCHAR *dest, const WCHAR *orig, size_t len)
{
wcsncpy(dest, orig, len);
}
-template<>
-static void __bcopy(WCHAR *dest, const char *orig, size_t len)
+inline void __bcopy(WCHAR *dest, const char *orig, size_t len)
{
MultiByteToWideChar(CallService("LangPack/GetCodePage", 0, 0), 0, orig, (int)len, dest, (int)len);
}
-template<>
-static void __bcopy(char *dest, const WCHAR *orig, size_t len)
+inline void __bcopy(char *dest, const WCHAR *orig, size_t len)
{
WideCharToMultiByte(CallService("LangPack/GetCodePage", 0, 0), 0, orig, (int)len, dest, (int)len, NULL, NULL);
}
diff --git a/src/core/stduserinfo/src/stdinfo.cpp b/src/core/stduserinfo/src/stdinfo.cpp index 8654746055..1dec08f526 100644 --- a/src/core/stduserinfo/src/stdinfo.cpp +++ b/src/core/stduserinfo/src/stdinfo.cpp @@ -37,28 +37,24 @@ INT_PTR CALLBACK ContactDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP static int Proto_GetContactInfoSetting(MCONTACT hContact, const char *szProto, const char *szModule, const char *szSetting, DBVARIANT *dbv, const int nType)
{
- DBCONTACTGETSETTING cgs = {szModule, szSetting, dbv};
+ DBCONTACTGETSETTING cgs = { szModule, szSetting, dbv };
dbv->type = (BYTE)nType;
return CallProtoService(szProto, PS_GETINFOSETTING, hContact, (LPARAM)&cgs);
}
-static void Proto_FreeInfoVariant(DBVARIANT *dbv)
+static TCHAR* Proto_GetContactInfoSettingStr(bool proto_service, MCONTACT hContact, const char *szModule, const char *szSetting)
{
- switch (dbv->type) {
- case DBVT_ASCIIZ:
- case DBVT_UTF8:
- case DBVT_WCHAR:
- mir_free(dbv->pszVal);
- dbv->pszVal = 0;
- break;
+ if (!proto_service)
+ return db_get_tsa(hContact, szModule, szSetting);
- case DBVT_BLOB:
- mir_free(dbv->pbVal);
- dbv->pbVal = 0;
- break;
- }
- dbv->type = 0;
+ DBVARIANT dbv;
+ DBCONTACTGETSETTING cgs = { szModule, szSetting, &dbv };
+ dbv.type = DBVT_TCHAR;
+ if (CallProtoService(szModule, PS_GETINFOSETTING, hContact, (LPARAM)&cgs))
+ return NULL;
+
+ return dbv.ptszVal;
}
static void SetValue(HWND hwndDlg, int idCtrl, MCONTACT hContact, char *szModule, char *szSetting, int special)
@@ -89,7 +85,7 @@ static void SetValue(HWND hwndDlg, int idCtrl, MCONTACT hContact, char *szModule else if (special == SVS_MONTH) {
if (dbv.bVal > 0 && dbv.bVal <= 12) {
pstr = str;
- GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SABBREVMONTHNAME1-1 + dbv.bVal, str, _countof(str));
+ GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SABBREVMONTHNAME1 - 1 + dbv.bVal, str, _countof(str));
}
else unspecified = 1;
}
@@ -174,15 +170,12 @@ static void SetValue(HWND hwndDlg, int idCtrl, MCONTACT hContact, char *szModule LBL_Exit:
EnableWindow(GetDlgItem(hwndDlg, idCtrl), !unspecified);
- if (proto_service)
- Proto_FreeInfoVariant(&dbv);
- else
- db_free(&dbv);
+ db_free(&dbv);
}
static INT_PTR CALLBACK SummaryDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
- switch(msg) {
+ switch (msg) {
case WM_INITDIALOG:
TranslateDialogDefault(hwndDlg);
break;
@@ -214,7 +207,7 @@ static INT_PTR CALLBACK SummaryDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LP break;
case WM_COMMAND:
- switch(LOWORD(wParam)) {
+ switch (LOWORD(wParam)) {
case IDCANCEL:
SendMessage(GetParent(hwndDlg), msg, wParam, lParam);
break;
@@ -234,7 +227,7 @@ static INT_PTR CALLBACK SummaryDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LP static INT_PTR CALLBACK LocationDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
- switch(msg) {
+ switch (msg) {
case WM_INITDIALOG:
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
@@ -287,7 +280,7 @@ static INT_PTR CALLBACK LocationDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, L break;
case WM_COMMAND:
- switch(LOWORD(wParam)) {
+ switch (LOWORD(wParam)) {
case IDCANCEL:
SendMessage(GetParent(hwndDlg), msg, wParam, lParam);
break;
@@ -307,7 +300,7 @@ static INT_PTR CALLBACK LocationDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, L static INT_PTR CALLBACK WorkDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
- switch(msg) {
+ switch (msg) {
case WM_INITDIALOG:
TranslateDialogDefault(hwndDlg);
break;
@@ -336,7 +329,7 @@ static INT_PTR CALLBACK WorkDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA break;
case WM_COMMAND:
- switch(LOWORD(wParam)) {
+ switch (LOWORD(wParam)) {
case IDCANCEL:
SendMessage(GetParent(hwndDlg), msg, wParam, lParam);
break;
@@ -358,25 +351,28 @@ static INT_PTR CALLBACK WorkDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA void ResizeColumns(HWND hwndLV)
{
int nCol = 0; LVCOLUMN lvCol;
- lvCol.mask = LVCF_WIDTH;
+ lvCol.mask = LVCF_WIDTH;
while (ListView_GetColumn(hwndLV, nCol++, &lvCol))
- ListView_SetColumnWidth(hwndLV, nCol-1, LVSCW_AUTOSIZE);
+ ListView_SetColumnWidth(hwndLV, nCol - 1, LVSCW_AUTOSIZE);
}
static INT_PTR CALLBACK BackgroundDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
- switch(msg) {
+ switch (msg) {
case WM_INITDIALOG:
TranslateDialogDefault(hwndDlg);
- { LVCOLUMN lvc;
+ {
RECT rc;
GetClientRect(GetDlgItem(hwndDlg, IDC_PAST), &rc);
- rc.right-=GetSystemMetrics(SM_CXVSCROLL);
+ rc.right -= GetSystemMetrics(SM_CXVSCROLL);
+
+ LVCOLUMN lvc;
lvc.mask = LVCF_WIDTH;
- lvc.cx = rc.right/3;
+ lvc.cx = rc.right / 3;
ListView_InsertColumn(GetDlgItem(hwndDlg, IDC_PAST), 0, &lvc);
ListView_InsertColumn(GetDlgItem(hwndDlg, IDC_INTERESTS), 0, &lvc);
- lvc.cx = rc.right-rc.right/3;
+
+ lvc.cx = rc.right - rc.right / 3;
ListView_InsertColumn(GetDlgItem(hwndDlg, IDC_PAST), 1, &lvc);
ListView_InsertColumn(GetDlgItem(hwndDlg, IDC_INTERESTS), 1, &lvc);
}
@@ -387,95 +383,87 @@ static INT_PTR CALLBACK BackgroundDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, case WM_NOTIFY:
switch (((LPNMHDR)lParam)->idFrom) {
case 0:
- if (((LPNMHDR)lParam)->code == PSN_INFOCHANGED)
- { LVITEM lvi;
- int i;
+ if (((LPNMHDR)lParam)->code == PSN_INFOCHANGED) {
+ LVITEM lvi;
char idstr[33];
- DBVARIANT dbv, dbvText;
MCONTACT hContact = (MCONTACT)((LPPSHNOTIFY)lParam)->lParam;
-
if (hContact != NULL) {
char *szProto = GetContactProto(hContact);
- if (szProto == NULL) break;
+ if (szProto == NULL)
+ break;
+
bool proto_service = (CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_4, 0) & PF4_INFOSETTINGSVC) == PF4_INFOSETTINGSVC;
SetValue(hwndDlg, IDC_WEBPAGE, hContact, szProto, "Homepage", SVS_ZEROISUNSPEC);
- //past
+ // past
ListView_DeleteAllItems(GetDlgItem(hwndDlg, IDC_PAST));
lvi.mask = LVIF_TEXT;
lvi.iSubItem = 0;
lvi.iItem = 0;
- for (i=0;;i++) {
+ for (int i = 0;; i++) {
mir_snprintf(idstr, "Past%d", i);
- if ((proto_service && Proto_GetContactInfoSetting(hContact, szProto, szProto, idstr, &dbv, DBVT_TCHAR)) ||
- ( !proto_service && db_get_ts(hContact, szProto, idstr, &dbv)))
- break;
+ ptrT tszColText(Proto_GetContactInfoSettingStr(proto_service, hContact, szProto, idstr));
+ if (tszColText == NULL)
+ break;
mir_snprintf(idstr, "Past%dText", i);
- if (db_get_ts(hContact, szProto, idstr, &dbvText))
- {if (proto_service) Proto_FreeInfoVariant(&dbv); else db_free(&dbv); break;}
- lvi.pszText = dbv.ptszVal;
+ ptrT tszText(db_get_tsa(hContact, szProto, idstr));
+ if (tszText == NULL)
+ break;
+
+ lvi.pszText = tszColText;
ListView_InsertItem(GetDlgItem(hwndDlg, IDC_PAST), &lvi);
- ListView_SetItemText(GetDlgItem(hwndDlg, IDC_PAST), lvi.iItem, 1, dbvText.ptszVal);
- db_free(&dbvText);
- if (proto_service)
- Proto_FreeInfoVariant(&dbv);
- else
- db_free(&dbv);
+ ListView_SetItemText(GetDlgItem(hwndDlg, IDC_PAST), lvi.iItem, 1, tszText);
lvi.iItem++;
}
- for (i=0;;i++) {
+ // affiliation
+ for (int i = 0;; i++) {
mir_snprintf(idstr, "Affiliation%d", i);
- if ((proto_service && Proto_GetContactInfoSetting(hContact, szProto, szProto, idstr, &dbv, DBVT_TCHAR)) ||
- ( !proto_service && db_get_ts(hContact, szProto, idstr, &dbv)))
+ ptrT tszColText(Proto_GetContactInfoSettingStr(proto_service, hContact, szProto, idstr));
+ if (tszColText == NULL)
break;
mir_snprintf(idstr, "Affiliation%dText", i);
- if (db_get_ts(hContact, szProto, idstr, &dbvText))
- {if (proto_service) Proto_FreeInfoVariant(&dbv); else db_free(&dbv); break;}
- lvi.pszText = dbv.ptszVal;
+ ptrT tszText(db_get_tsa(hContact, szProto, idstr));
+ if (tszText == NULL)
+ break;
+
+ lvi.pszText = tszColText;
ListView_InsertItem(GetDlgItem(hwndDlg, IDC_PAST), &lvi);
- ListView_SetItemText(GetDlgItem(hwndDlg, IDC_PAST), lvi.iItem, 1, dbvText.ptszVal);
- db_free(&dbvText);
- if (proto_service)
- Proto_FreeInfoVariant(&dbv);
- else
- db_free(&dbv);
+ ListView_SetItemText(GetDlgItem(hwndDlg, IDC_PAST), lvi.iItem, 1, tszText);
lvi.iItem++;
}
ResizeColumns(GetDlgItem(hwndDlg, IDC_PAST));
- //interests
+ // interests
ListView_DeleteAllItems(GetDlgItem(hwndDlg, IDC_INTERESTS));
lvi.mask = LVIF_TEXT;
lvi.iSubItem = 0;
lvi.iItem = 0;
- for (i=0;;i++) {
+ for (int i = 0;; i++) {
mir_snprintf(idstr, "Interest%dCat", i);
- if ((proto_service && Proto_GetContactInfoSetting(hContact, szProto, szProto, idstr, &dbv, DBVT_TCHAR)) ||
- ( !proto_service && db_get_ts(hContact, szProto, idstr, &dbv)))
+ ptrT tszColText(Proto_GetContactInfoSettingStr(proto_service, hContact, szProto, idstr));
+ if (tszColText == NULL)
break;
mir_snprintf(idstr, "Interest%dText", i);
- if (db_get_ts(hContact, szProto, idstr, &dbvText))
- {if (proto_service) Proto_FreeInfoVariant(&dbv); else db_free(&dbv); break;}
- lvi.pszText = dbv.ptszVal;
+ ptrT tszText(db_get_tsa(hContact, szProto, idstr));
+ if (tszText == NULL)
+ break;
+
+ lvi.pszText = tszColText;
ListView_InsertItem(GetDlgItem(hwndDlg, IDC_INTERESTS), &lvi);
- ListView_SetItemText(GetDlgItem(hwndDlg, IDC_INTERESTS), lvi.iItem, 1, dbvText.ptszVal);
- db_free(&dbvText);
- if (proto_service)
- Proto_FreeInfoVariant(&dbv);
- else
- db_free(&dbv);
+ ListView_SetItemText(GetDlgItem(hwndDlg, IDC_INTERESTS), lvi.iItem, 1, tszText);
lvi.iItem++;
}
ResizeColumns(GetDlgItem(hwndDlg, IDC_INTERESTS));
- } }
+ }
+ }
break;
}
break;
case WM_COMMAND:
- switch(LOWORD(wParam)) {
+ switch (LOWORD(wParam)) {
case IDCANCEL:
SendMessage(GetParent(hwndDlg), msg, wParam, lParam);
break;
@@ -494,13 +482,14 @@ static INT_PTR CALLBACK BackgroundDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, static INT_PTR CALLBACK NotesDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
- switch(msg) {
+ MCONTACT hContact;
+
+ switch (msg) {
case WM_INITDIALOG:
TranslateDialogDefault(hwndDlg);
- { DBVARIANT dbv;
- HFONT hFont;
- LOGFONT lf;
+ {
HDC hDC = GetDC(hwndDlg);
+ LOGFONT lf;
lf.lfHeight = -MulDiv(10, GetDeviceCaps(hDC, LOGPIXELSY), 72);
ReleaseDC(hwndDlg, hDC);
lf.lfWidth = 0;
@@ -516,56 +505,52 @@ static INT_PTR CALLBACK NotesDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
mir_tstrcpy(lf.lfFaceName, _T("Courier New"));
lf.lfCharSet = DEFAULT_CHARSET;
- hFont = CreateFontIndirect(&lf);
- SendDlgItemMessage(hwndDlg, IDC_ABOUT, WM_SETFONT, (WPARAM) hFont, MAKELPARAM(TRUE, 0));
+ HFONT hFont = CreateFontIndirect(&lf);
+ SendDlgItemMessage(hwndDlg, IDC_ABOUT, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0));
- if (!db_get_s(lParam, "UserInfo", "MyNotes", &dbv)) {
- SetDlgItemTextA(hwndDlg, IDC_MYNOTES, dbv.pszVal);
- db_free(&dbv);
- }
+ ptrT szNotes(db_get_tsa(lParam, "UserInfo", "MyNotes"));
+ if (szNotes != nullptr)
+ SetDlgItemText(hwndDlg, IDC_MYNOTES, szNotes);
}
SendDlgItemMessage(hwndDlg, IDC_MYNOTES, EM_LIMITTEXT, 2048, 0);
break;
+
case WM_NOTIFY:
switch (((LPNMHDR)lParam)->idFrom) {
case 0:
switch (((LPNMHDR)lParam)->code) {
case PSN_INFOCHANGED:
- {
- MCONTACT hContact = (MCONTACT)((LPPSHNOTIFY)lParam)->lParam;
- if (hContact != NULL) {
- char *szProto = GetContactProto(hContact);
- if (szProto != NULL)
- SetValue(hwndDlg, IDC_ABOUT, hContact, szProto, "About", 0);
- }
+ hContact = (MCONTACT)((LPPSHNOTIFY)lParam)->lParam;
+ if (hContact != NULL) {
+ char *szProto = GetContactProto(hContact);
+ if (szProto != NULL)
+ SetValue(hwndDlg, IDC_ABOUT, hContact, szProto, "About", 0);
}
break;
+
case PSN_APPLY:
- {
- MCONTACT hContact = (MCONTACT)((LPPSHNOTIFY)lParam)->lParam;
- if (GetWindowTextLength(GetDlgItem(hwndDlg, IDC_MYNOTES))) {
- char text[2048];
- GetDlgItemTextA(hwndDlg, IDC_MYNOTES, text, _countof(text));
- db_set_s(hContact, "UserInfo", "MyNotes", text);
- }
- else db_unset(hContact, "UserInfo", "MyNotes");
+ hContact = (MCONTACT)((LPPSHNOTIFY)lParam)->lParam;
+ if (GetWindowTextLength(GetDlgItem(hwndDlg, IDC_MYNOTES))) {
+ char text[2048];
+ GetDlgItemTextA(hwndDlg, IDC_MYNOTES, text, _countof(text));
+ db_set_s(hContact, "UserInfo", "MyNotes", text);
}
+ else db_unset(hContact, "UserInfo", "MyNotes");
break;
}
break;
}
break;
+
case WM_COMMAND:
if (wParam == MAKEWPARAM(IDC_MYNOTES, EN_CHANGE))
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
else if (LOWORD(wParam) == IDCANCEL)
SendMessage(GetParent(hwndDlg), msg, wParam, lParam);
break;
+
case WM_DESTROY:
- {
- HFONT hFont = (HFONT)SendDlgItemMessage(hwndDlg, IDC_ABOUT, WM_GETFONT, 0, 0);
- DeleteObject(hFont);
- }
+ DeleteObject((HFONT)SendDlgItemMessage(hwndDlg, IDC_ABOUT, WM_GETFONT, 0, 0));
break;
}
return FALSE;
@@ -591,7 +576,7 @@ int DetailsInit(WPARAM wParam, LPARAM lParam) odp.pfnDlgProc = ContactDlgProc;
odp.position = -1800000000;
odp.pszTemplate = MAKEINTRESOURCEA(IDD_INFO_CONTACT);
- odp.pszTitle = LPGEN("Contact");
+ odp.pszTitle = LPGEN("Contact");
UserInfo_AddPage(wParam, &odp);
odp.pfnDlgProc = LocationDlgProc;
|