summaryrefslogtreecommitdiff
path: root/plugins/SimpleStatusMsg
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 /plugins/SimpleStatusMsg
parent41b2fdfc654e3eec07c97ceba00cda13d988ffff (diff)
db_get_sa / db_get_wsa to receive the default value, massive code simplification
Diffstat (limited to 'plugins/SimpleStatusMsg')
-rw-r--r--plugins/SimpleStatusMsg/src/awaymsg.cpp2
-rw-r--r--plugins/SimpleStatusMsg/src/main.cpp4
-rw-r--r--plugins/SimpleStatusMsg/src/msgbox.cpp4
-rw-r--r--plugins/SimpleStatusMsg/src/options.cpp48
4 files changed, 13 insertions, 45 deletions
diff --git a/plugins/SimpleStatusMsg/src/awaymsg.cpp b/plugins/SimpleStatusMsg/src/awaymsg.cpp
index 41e30468cf..c88c2d96be 100644
--- a/plugins/SimpleStatusMsg/src/awaymsg.cpp
+++ b/plugins/SimpleStatusMsg/src/awaymsg.cpp
@@ -307,7 +307,7 @@ static int AwayMsgPreBuildMenu(WPARAM hContact, LPARAM)
IcoLib_ReleaseIcon(hIcon);
ptrA szMsg(db_get_sa(hContact, "CList", "StatusMsg"));
- if (szMsg != NULL) {
+ if (szMsg != nullptr) {
mir_snwprintf(str, TranslateT("Copy %s message"), Clist_GetStatusModeDescription(iStatus, 0));
Menu_ModifyItem(hCopyMsgMenuItem, str);
diff --git a/plugins/SimpleStatusMsg/src/main.cpp b/plugins/SimpleStatusMsg/src/main.cpp
index 72a36008a4..aac8d8d7bf 100644
--- a/plugins/SimpleStatusMsg/src/main.cpp
+++ b/plugins/SimpleStatusMsg/src/main.cpp
@@ -346,7 +346,7 @@ static wchar_t* GetAwayMessageFormat(int iStatus, const char *szProto)
else
mir_snprintf(szSetting, "Msg");
- format = db_get_wsa(NULL, "SRAway", StatusModeToDbSetting(iStatus, szSetting));
+ format = db_get_wsa(0, "SRAway", StatusModeToDbSetting(iStatus, szSetting));
}
else if (flags & STATUS_LAST_MSG) {
if (szProto)
@@ -367,7 +367,7 @@ static wchar_t* GetAwayMessageFormat(int iStatus, const char *szProto)
else
mir_snprintf(szSetting, "Default");
- format = db_get_wsa(NULL, "SRAway", StatusModeToDbSetting(iStatus, szSetting));
+ format = db_get_wsa(0, "SRAway", StatusModeToDbSetting(iStatus, szSetting));
if (format == nullptr)
format = mir_wstrdup(L"");
}
diff --git a/plugins/SimpleStatusMsg/src/msgbox.cpp b/plugins/SimpleStatusMsg/src/msgbox.cpp
index b47581c636..8a50c8f9d7 100644
--- a/plugins/SimpleStatusMsg/src/msgbox.cpp
+++ b/plugins/SimpleStatusMsg/src/msgbox.cpp
@@ -746,7 +746,7 @@ void SetEditControlText(struct MsgBoxData *data, HWND hwndDlg, int iStatus)
else
mir_snprintf(setting, "Default");
- wchar_t *tszStatusMsg = db_get_wsa(NULL, "SRAway", StatusModeToDbSetting(iStatus, setting));
+ wchar_t *tszStatusMsg = db_get_wsa(0, "SRAway", StatusModeToDbSetting(iStatus, setting));
if (tszStatusMsg != nullptr) {
SetDlgItemText(hwndDlg, IDC_EDIT1, tszStatusMsg);
fcursel = SendMessage(data->recent_cbex, CB_FINDSTRINGEXACT, num_start, (LPARAM)tszStatusMsg);
@@ -761,7 +761,7 @@ void SetEditControlText(struct MsgBoxData *data, HWND hwndDlg, int iStatus)
else
mir_snprintf(setting, "Msg");
- wchar_t *tszStatusMsg = db_get_wsa(NULL, "SRAway", StatusModeToDbSetting(iStatus, setting));
+ wchar_t *tszStatusMsg = db_get_wsa(0, "SRAway", StatusModeToDbSetting(iStatus, setting));
if (tszStatusMsg != nullptr) {
SetDlgItemText(hwndDlg, IDC_EDIT1, tszStatusMsg);
fcursel = SendMessage(data->recent_cbex, CB_FINDSTRINGEXACT, num_start, (LPARAM)tszStatusMsg);
diff --git a/plugins/SimpleStatusMsg/src/options.cpp b/plugins/SimpleStatusMsg/src/options.cpp
index e208c19ca8..e5cdae1fde 100644
--- a/plugins/SimpleStatusMsg/src/options.cpp
+++ b/plugins/SimpleStatusMsg/src/options.cpp
@@ -133,8 +133,8 @@ INT_PTR CALLBACK DlgOptionsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l
val = g_plugin.getByte((char *)StatusModeToDbSetting(i, "Flags"), STATUS_DEFAULT);
data->status_msg[0].flags[i - ID_STATUS_ONLINE] = val;
- ptrW text(db_get_wsa(NULL, "SRAway", StatusModeToDbSetting(i, "Default")));
- mir_wstrncpy(data->status_msg[0].msg[i - ID_STATUS_ONLINE], (text == NULL) ? GetDefaultMessage(i) : text, 1024);
+ ptrW text(db_get_wsa(0, "SRAway", StatusModeToDbSetting(i, "Default"), GetDefaultMessage(i)));
+ mir_wstrncpy(data->status_msg[0].msg[i - ID_STATUS_ONLINE], text, 1024);
for (j = 0; j < accounts->count; j++) {
auto *pa = accounts->pa[j];
@@ -145,8 +145,8 @@ INT_PTR CALLBACK DlgOptionsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l
val = g_plugin.getByte((char *)StatusModeToDbSetting(i, setting), STATUS_DEFAULT);
data->status_msg[j + 1].flags[i - ID_STATUS_ONLINE] = val;
mir_snprintf(setting, "%sDefault", pa->szModuleName);
- text = db_get_wsa(NULL, "SRAway", StatusModeToDbSetting(i, setting));
- mir_wstrncpy(data->status_msg[j + 1].msg[i - ID_STATUS_ONLINE], (text == NULL) ? GetDefaultMessage(i) : text, 1024);
+ text = db_get_wsa(0, "SRAway", StatusModeToDbSetting(i, setting), GetDefaultMessage(i));
+ mir_wstrncpy(data->status_msg[j + 1].msg[i - ID_STATUS_ONLINE], text, 1024);
}
}
}
@@ -446,19 +446,11 @@ INT_PTR CALLBACK DlgOptionsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l
}
else if (data->status_msg[i].flags[j] & STATUS_LAST_STATUS_MSG) {
char setting[80];
-
if (i)
mir_snprintf(setting, "%sMsg", accounts->pa[k]->szModuleName);
else
mir_snprintf(setting, "Msg");
-
- wchar_t *tszStatusMsg = db_get_wsa(NULL, "SRAway", StatusModeToDbSetting(j + ID_STATUS_ONLINE, setting));
- if (tszStatusMsg) {
- SetDlgItemText(hwndDlg, IDC_OPTEDIT1, tszStatusMsg);
- mir_free(tszStatusMsg);
- }
- else
- SetDlgItemText(hwndDlg, IDC_OPTEDIT1, L"");
+ SetDlgItemText(hwndDlg, IDC_OPTEDIT1, ptrW(db_get_wsa(0, "SRAway", StatusModeToDbSetting(j + ID_STATUS_ONLINE, setting), L"")));
EnableWindow(GetDlgItem(hwndDlg, IDC_OPTEDIT1), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_VARSHELP), FALSE);
@@ -582,19 +574,11 @@ INT_PTR CALLBACK DlgOptionsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l
}
else if (data->status_msg[i].flags[j] & STATUS_LAST_STATUS_MSG) {
char setting[80];
-
if (i)
mir_snprintf(setting, "%sMsg", accounts->pa[i - 1]->szModuleName);
else
mir_snprintf(setting, "Msg");
-
- wchar_t *tszStatusMsg = db_get_wsa(NULL, "SRAway", StatusModeToDbSetting(j + ID_STATUS_ONLINE, setting));
- if (tszStatusMsg != nullptr) {
- SetDlgItemText(hwndDlg, IDC_OPTEDIT1, tszStatusMsg);
- mir_free(tszStatusMsg);
- }
- else
- SetDlgItemText(hwndDlg, IDC_OPTEDIT1, L"");
+ SetDlgItemText(hwndDlg, IDC_OPTEDIT1, ptrW(db_get_wsa(0, "SRAway", StatusModeToDbSetting(j + ID_STATUS_ONLINE, setting), L"")));
EnableWindow(GetDlgItem(hwndDlg, IDC_OPTEDIT1), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_VARSHELP), FALSE);
@@ -661,19 +645,11 @@ INT_PTR CALLBACK DlgOptionsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l
}
else if (data->status_msg[j].flags[i] & STATUS_LAST_STATUS_MSG) {
char setting[80];
-
if (j)
mir_snprintf(setting, "%sMsg", accounts->pa[j - 1]->szModuleName);
else
mir_snprintf(setting, "Msg");
-
- wchar_t *tszStatusMsg = db_get_wsa(NULL, "SRAway", StatusModeToDbSetting(j + ID_STATUS_ONLINE, setting));
- if (tszStatusMsg != nullptr) {
- SetDlgItemText(hwndDlg, IDC_OPTEDIT1, tszStatusMsg);
- mir_free(tszStatusMsg);
- }
- else
- SetDlgItemText(hwndDlg, IDC_OPTEDIT1, L"");
+ SetDlgItemText(hwndDlg, IDC_OPTEDIT1, db_get_wsa(0, "SRAway", StatusModeToDbSetting(j + ID_STATUS_ONLINE, setting), L""));
EnableWindow(GetDlgItem(hwndDlg, IDC_OPTEDIT1), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_VARSHELP), FALSE);
@@ -764,19 +740,11 @@ INT_PTR CALLBACK DlgOptionsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l
}
else if (LOWORD(wParam) == IDC_ROPTMSG5) {
char setting[80];
-
if (j)
mir_snprintf(setting, "%sMsg", accounts->pa[j - 1]->szModuleName);
else
mir_snprintf(setting, "Msg");
-
- wchar_t *tszStatusMsg = db_get_wsa(NULL, "SRAway", StatusModeToDbSetting(i + ID_STATUS_ONLINE, setting));
- if (tszStatusMsg != nullptr) {
- SetDlgItemText(hwndDlg, IDC_OPTEDIT1, tszStatusMsg);
- mir_free(tszStatusMsg);
- }
- else
- SetDlgItemText(hwndDlg, IDC_OPTEDIT1, L"");
+ SetDlgItemText(hwndDlg, IDC_OPTEDIT1, ptrW(db_get_wsa(0, "SRAway", StatusModeToDbSetting(i + ID_STATUS_ONLINE, setting), L"")));
EnableWindow(GetDlgItem(hwndDlg, IDC_OPTEDIT1), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_VARSHELP), FALSE);