From 8ffc77be71507825a8f7585bcabff8ccc370206a Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 8 Dec 2018 20:12:16 +0300 Subject: db_get_sa / db_get_wsa to receive the default value, massive code simplification --- src/mir_app/src/chat_opts.cpp | 6 +----- src/mir_app/src/chat_tools.cpp | 3 +-- src/mir_app/src/clistsettings.cpp | 7 ++----- src/mir_app/src/menu_options.cpp | 5 +---- 4 files changed, 5 insertions(+), 16 deletions(-) (limited to 'src/mir_app') diff --git a/src/mir_app/src/chat_opts.cpp b/src/mir_app/src/chat_opts.cpp index 30145b13b3..450a1629c7 100644 --- a/src/mir_app/src/chat_opts.cpp +++ b/src/mir_app/src/chat_opts.cpp @@ -121,11 +121,7 @@ void LoadMsgDlgFont(int i, LOGFONT *lf, COLORREF *colour) lf->lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; mir_snprintf(str, "Font%d", i); - ptrW tszFace(db_get_wsa(0, CHATFONT_MODULE, str)); - if (tszFace == nullptr) - mir_wstrcpy(lf->lfFaceName, FO.szDefFace); - else - wcsncpy_s(lf->lfFaceName, tszFace, _TRUNCATE); + wcsncpy_s(lf->lfFaceName, ptrW(db_get_wsa(0, CHATFONT_MODULE, str, FO.szDefFace)), _TRUNCATE); } } diff --git a/src/mir_app/src/chat_tools.cpp b/src/mir_app/src/chat_tools.cpp index deba485f86..93895418a5 100644 --- a/src/mir_app/src/chat_tools.cpp +++ b/src/mir_app/src/chat_tools.cpp @@ -687,8 +687,7 @@ wchar_t* GetChatLogsFilename(SESSION_INFO *si, time_t tTime) MIR_APP_DLL(wchar_t*) Chat_GetGroup() { - ptrW pszGroup(db_get_wsa(0, CHAT_MODULE, "AddToGroup")); - return (pszGroup) ? pszGroup.detach() : mir_wstrdup(TranslateT("Chat rooms")); + return db_get_wsa(0, CHAT_MODULE, "AddToGroup", TranslateT("Chat rooms")); } MIR_APP_DLL(void) Chat_SetGroup(const wchar_t *pwszGroupName) diff --git a/src/mir_app/src/clistsettings.cpp b/src/mir_app/src/clistsettings.cpp index 37fb40cd66..fa5dab7d14 100644 --- a/src/mir_app/src/clistsettings.cpp +++ b/src/mir_app/src/clistsettings.cpp @@ -62,11 +62,8 @@ ClcCacheEntry* fnCreateCacheItem(MCONTACT hContact) void fnCheckCacheItem(ClcCacheEntry *p) { - if (p->tszGroup == nullptr) { - p->tszGroup = db_get_wsa(p->hContact, "CList", "Group"); - if (p->tszGroup == nullptr) - p->tszGroup = mir_wstrdup(L""); - } + if (p->tszGroup == nullptr) + p->tszGroup = db_get_wsa(p->hContact, "CList", "Group", L""); if (p->szProto == nullptr) p->szProto = GetContactProto(p->hContact); diff --git a/src/mir_app/src/menu_options.cpp b/src/mir_app/src/menu_options.cpp index a574e704c4..4799285e90 100644 --- a/src/mir_app/src/menu_options.cpp +++ b/src/mir_app/src/menu_options.cpp @@ -41,10 +41,7 @@ MIR_APP_DLL(void) Menu_SetVisible(TMO_IntMenuItem *pimi, bool bVisible) mir_snprintf(szModule, "%s_Items", pimi->parent->pszName); bin2hex(&pimi->mi.uid, sizeof(pimi->mi.uid), menuItemName); - ptrW wszValue(db_get_wsa(0, szModule, menuItemName)); - if (wszValue == nullptr) - wszValue = mir_wstrdup(L"1;;;"); - + ptrW wszValue(db_get_wsa(0, szModule, menuItemName, L"1;;;")); wszValue[0] = bVisible ? '1' : '0'; db_set_ws(0, szModule, menuItemName, wszValue); -- cgit v1.2.3