diff options
author | George Hazan <george.hazan@gmail.com> | 2023-08-10 12:02:31 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2023-08-10 12:02:31 +0300 |
commit | 3187428bb2f7b929e31ebf64b1e21d9c0fbc4f2b (patch) | |
tree | fa1704b43d0a1c5b3c7b67f1e4f9f8142f39d0be /plugins/NewStory/src/templates.cpp | |
parent | 258cb3c6a167d7f3ca125de2d7ba70ea2ef65a63 (diff) |
NewStory: memory leak fix + small quirks fixed
Diffstat (limited to 'plugins/NewStory/src/templates.cpp')
-rw-r--r-- | plugins/NewStory/src/templates.cpp | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/plugins/NewStory/src/templates.cpp b/plugins/NewStory/src/templates.cpp index 451342034e..87c3faf9de 100644 --- a/plugins/NewStory/src/templates.cpp +++ b/plugins/NewStory/src/templates.cpp @@ -150,11 +150,11 @@ void vfEvent(int, TemplateVars *vars, MCONTACT, ItemData *item) if (item->dbe.flags & DBEF_SENT) { char *proto = Proto_GetBaseAccountName(item->hContact); ptrW nick(Contact::GetInfo(CNF_DISPLAY, 0, proto)); - vars->SetVar('N', nick, false); + vars->SetNick(nick, false); } else { wchar_t *nick = (item->wszNick) ? item->wszNick : Clist_GetContactDisplayName(item->hContact, 0); - vars->SetVar('N', nick, false); + vars->SetNick(nick, true); } // %I: Icon @@ -200,10 +200,9 @@ void vfEvent(int, TemplateVars *vars, MCONTACT, ItemData *item) if (!TimeZone_GetSystemTime(nullptr, item->dbe.timestamp, &st, 0)) { int iLocale = Langpack_GetDefaultLocale(); - CMStringW tmp; - GetDateFormatW(iLocale, 0, &st, L"dd.MM.yyyy, ", buf, _countof(buf)); tmp += buf; - GetTimeFormatW(iLocale, 0, &st, L"HH:mm", buf, _countof(buf)); tmp += buf; - vars->SetVar('t', tmp, true); + GetDateFormatW(iLocale, 0, &st, L"dd.MM.yyyy, ", buf, _countof(buf)); + GetTimeFormatW(iLocale, 0, &st, L"HH:mm", buf + 12, _countof(buf)); + vars->SetVar('t', buf, true); // %h: hour (24 hour format, 0-23) GetTimeFormatW(iLocale, 0, &st, L"HH", buf, _countof(buf)); @@ -295,6 +294,29 @@ void vfOther(int, TemplateVars *vars, MCONTACT, ItemData *item) ///////////////////////////////////////////////////////////////////////////////////////// +void TemplateVars::SetNick(wchar_t *v, bool bIncoming) +{ + CMStringW wszNick(FORMAT, L"[color=%d]%s[/color]", g_colorTable[(bIncoming) ? COLOR_INNICK : COLOR_OUTNICK].cl, v); + + auto &V = vars['N']; + if (V.del) + mir_free(V.val); + V.val = wszNick.Detach(); + V.del = true; +} + +void TemplateVars::SetVar(uint8_t id, wchar_t *v, bool d) +{ + auto &V = vars[id]; + if (V.del) + mir_free(V.val); + + V.val = (d) ? mir_wstrdup(v) : v; + V.del = d; +} + +///////////////////////////////////////////////////////////////////////////////////////// + HICON TemplateInfo::getIcon() const { return (iIcon < 0) ? Skin_LoadIcon(-iIcon) : g_plugin.getIcon(iIcon); |