summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-12-08 20:12:16 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-12-08 20:12:26 +0300
commit8ffc77be71507825a8f7585bcabff8ccc370206a (patch)
treeaa13a8070f31286db6ad22e17a577e547942f951 /src
parent41b2fdfc654e3eec07c97ceba00cda13d988ffff (diff)
db_get_sa / db_get_wsa to receive the default value, massive code simplification
Diffstat (limited to 'src')
-rw-r--r--src/mir_app/src/chat_opts.cpp6
-rw-r--r--src/mir_app/src/chat_tools.cpp3
-rw-r--r--src/mir_app/src/clistsettings.cpp7
-rw-r--r--src/mir_app/src/menu_options.cpp5
-rw-r--r--src/mir_core/src/db.cpp26
-rw-r--r--src/mir_core/src/openurl.cpp2
6 files changed, 21 insertions, 28 deletions
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);
diff --git a/src/mir_core/src/db.cpp b/src/mir_core/src/db.cpp
index 87eb0ed80c..eef66081df 100644
--- a/src/mir_core/src/db.cpp
+++ b/src/mir_core/src/db.cpp
@@ -163,22 +163,26 @@ MIR_CORE_DLL(INT_PTR) db_get_s(MCONTACT hContact, const char *szModule, const ch
return currDb->GetContactSettingStr(hContact, szModule, szSetting, dbv);
}
-MIR_CORE_DLL(char*) db_get_sa(MCONTACT hContact, const char *szModule, const char *szSetting)
+MIR_CORE_DLL(char*) db_get_sa(MCONTACT hContact, const char *szModule, const char *szSetting, const char *szValue)
{
- if (currDb == nullptr)
- return nullptr;
+ if (currDb) {
+ DBVARIANT dbv = { DBVT_ASCIIZ };
+ if (!currDb->GetContactSettingStr(hContact, szModule, szSetting, &dbv))
+ return dbv.pszVal;
+ }
- DBVARIANT dbv = { DBVT_ASCIIZ };
- return currDb->GetContactSettingStr(hContact, szModule, szSetting, &dbv) ? nullptr : dbv.pszVal;
+ return (szValue == nullptr) ? nullptr : mir_strdup(szValue);
}
-MIR_CORE_DLL(wchar_t*) db_get_wsa(MCONTACT hContact, const char *szModule, const char *szSetting)
+MIR_CORE_DLL(wchar_t*) db_get_wsa(MCONTACT hContact, const char *szModule, const char *szSetting, const wchar_t *szValue)
{
- if (currDb == nullptr)
- return nullptr;
+ if (currDb) {
+ DBVARIANT dbv = { DBVT_WCHAR };
+ if (!currDb->GetContactSettingStr(hContact, szModule, szSetting, &dbv))
+ return dbv.pwszVal;
+ }
- DBVARIANT dbv = { DBVT_WCHAR };
- return currDb->GetContactSettingStr(hContact, szModule, szSetting, &dbv) ? nullptr : dbv.pwszVal;
+ return (szValue == nullptr) ? nullptr : mir_wstrdup(szValue);
}
MIR_CORE_DLL(CMStringA) db_get_sm(MCONTACT hContact, LPCSTR szModule, LPCSTR szSetting)
@@ -459,7 +463,7 @@ MIR_CORE_DLL(void) db_setCurrent(MDatabaseCommon *_db)
return;
// try to get the langpack's name from a profile
- ptrW langpack(db_get_wsa(NULL, "Langpack", "Current"));
+ ptrW langpack(db_get_wsa(0, "Langpack", "Current"));
if (langpack && langpack[0] != '\0')
LoadLangPack(langpack);
else
diff --git a/src/mir_core/src/openurl.cpp b/src/mir_core/src/openurl.cpp
index 2fcd374dce..94fdabd3fd 100644
--- a/src/mir_core/src/openurl.cpp
+++ b/src/mir_core/src/openurl.cpp
@@ -54,7 +54,7 @@ static void __cdecl OpenURLThread(TOpenUrlInfo *hUrlInfo)
}
// check user defined browser for opening urls
- ptrW tszBrowser(db_get_wsa(NULL, "Miranda", "OpenUrlBrowser"));
+ ptrW tszBrowser(db_get_wsa(0, "Miranda", "OpenUrlBrowser"));
if (tszBrowser)
ShellExecute(nullptr, L"open", tszBrowser, tszUrl, nullptr, (hUrlInfo->newWindow) ? SW_NORMAL : SW_SHOWDEFAULT);
else