summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2015-09-01 10:57:44 +0000
committerGeorge Hazan <george.hazan@gmail.com>2015-09-01 10:57:44 +0000
commit5a28a5996189fe3771799388ead1e26e64062494 (patch)
treeb401cbfc1178f5aa40d379c76c68e0bd42cb2934 /plugins
parent0ed4c703d7de168e5f59c84cb7d447a42e27877e (diff)
- %g added to tabSRMM window header's masks -> users's group;
- code optimization git-svn-id: http://svn.miranda-ng.org/main/trunk@15132 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins')
-rw-r--r--plugins/TabSRMM/src/container.cpp8
-rw-r--r--plugins/TabSRMM/src/utils.cpp122
-rw-r--r--plugins/TabSRMM/src/utils.h4
3 files changed, 41 insertions, 93 deletions
diff --git a/plugins/TabSRMM/src/container.cpp b/plugins/TabSRMM/src/container.cpp
index 877f742a1d..01a14c266f 100644
--- a/plugins/TabSRMM/src/container.cpp
+++ b/plugins/TabSRMM/src/container.cpp
@@ -1040,11 +1040,9 @@ panel_found:
}
if (dat) {
SendMessage(hwndDlg, DM_SETICON, (WPARAM)dat, (LPARAM)(dat->hXStatusIcon ? dat->hXStatusIcon : dat->hTabStatusIcon));
- TCHAR *szNewTitle = Utils::FormatTitleBar(dat, pContainer->settings->szTitleFormat);
- if (szNewTitle) {
- SetWindowText(hwndDlg, szNewTitle);
- mir_free(szNewTitle);
- }
+ CMString szTitle;
+ if (Utils::FormatTitleBar(dat, pContainer->settings->szTitleFormat, szTitle))
+ SetWindowText(hwndDlg, szTitle);
}
return 0;
diff --git a/plugins/TabSRMM/src/utils.cpp b/plugins/TabSRMM/src/utils.cpp
index 178c944282..bad2772b2c 100644
--- a/plugins/TabSRMM/src/utils.cpp
+++ b/plugins/TabSRMM/src/utils.cpp
@@ -265,121 +265,73 @@ ok:
/////////////////////////////////////////////////////////////////////////////////////////
// format the title bar string for IM chat sessions using placeholders.
// the caller must mir_free() the returned string
-TCHAR* Utils::FormatTitleBar(const TWindowData *dat, const TCHAR *szFormat)
+
+static TCHAR* Trunc500(TCHAR *str)
{
- INT_PTR tempmark = 0;
- TCHAR szTemp[512];
+ if (mir_tstrlen(str) > 500)
+ str[500] = 0;
+ return str;
+}
+bool Utils::FormatTitleBar(const TWindowData *dat, const TCHAR *szFormat, CMString &dest)
+{
if (dat == 0)
- return 0;
-
- tstring title(szFormat);
+ return false;
- for (size_t curpos = 0; curpos < title.length();) {
- if (title[curpos] != '%') {
- curpos++;
+ for (const TCHAR *src = szFormat; *src; src++) {
+ if (*src != '%') {
+ dest.AppendChar(*src);
continue;
}
- tempmark = curpos;
- curpos++;
- if (title[curpos] == 0)
- break;
- const TCHAR *p;
- switch (title[curpos]) {
+ switch (*++src) {
case 'n':
- p = dat->cache->getNick();
- if (p[0])
- title.insert(tempmark + 2, p);
- title.erase(tempmark, 2);
- curpos = tempmark + mir_tstrlen(p);
+ dest.Append(dat->cache->getNick());
break;
+
case 'p':
case 'a':
- p = dat->cache->getRealAccount();
- if (p)
- title.insert(tempmark + 2, p);
- title.erase(tempmark, 2);
- curpos = tempmark + mir_tstrlen(p);
+ dest.Append(dat->cache->getRealAccount());
break;
case 's':
- if (dat->szStatus[0])
- title.insert(tempmark + 2, dat->szStatus);
- title.erase(tempmark, 2);
- curpos = tempmark + mir_tstrlen(dat->szStatus);
+ dest.Append(dat->szStatus);
break;
case 'u':
- p = dat->cache->getUIN();
- if (p[0])
- title.insert(tempmark + 2, p);
- title.erase(tempmark, 2);
- curpos = tempmark + mir_tstrlen(p);
+ dest.Append(dat->cache->getUIN());
break;
case 'c':
- p = (!mir_tstrcmp(dat->pContainer->szName, _T("default")) ? TranslateT("Default container") : dat->pContainer->szName);
- title.insert(tempmark + 2, p);
- title.erase(tempmark, 2);
- curpos = tempmark + mir_tstrlen(p);
+ dest.Append(!mir_tstrcmp(dat->pContainer->szName, _T("default")) ? TranslateT("Default container") : dat->pContainer->szName);
break;
case 'o':
{
const char *szProto = dat->cache->getActiveProto();
if (szProto)
- title.insert(tempmark + 2, _A2T(szProto));
- title.erase(tempmark, 2);
- curpos = tempmark + (szProto ? mir_strlen(szProto) : 0);
+ dest.Append(_A2T(szProto));
}
break;
case 'x':
{
BYTE xStatus = dat->cache->getXStatusId();
-
if (dat->wStatus != ID_STATUS_OFFLINE && xStatus > 0 && xStatus <= 31) {
- DBVARIANT dbv = { 0 };
- if (!db_get_ts(dat->hContact, (char *)dat->szProto, "XStatusName", &dbv)) {
- _tcsncpy(szTemp, dbv.ptszVal, 500);
- szTemp[500] = 0;
- db_free(&dbv);
- title.insert(tempmark + 2, szTemp);
- curpos = tempmark + mir_tstrlen(szTemp);
- }
- else {
- title.insert(tempmark + 2, xStatusDescr[xStatus - 1]);
- curpos = tempmark + mir_tstrlen(xStatusDescr[xStatus - 1]);
- }
+ ptrT szXStatus(db_get_tsa(dat->hContact, dat->szProto, "XStatusName"));
+ dest.Append((szXStatus != NULL) ? Trunc500(szXStatus) : xStatusDescr[xStatus - 1]);
}
- title.erase(tempmark, 2);
}
break;
case 'm':
- p = NULL;
{
BYTE xStatus = dat->cache->getXStatusId();
if (dat->wStatus != ID_STATUS_OFFLINE && xStatus > 0 && xStatus <= 31) {
- DBVARIANT dbv = { 0 };
-
- if (!db_get_ts(dat->hContact, (char *)dat->szProto, "XStatusName", &dbv)) {
- _tcsncpy(szTemp, dbv.ptszVal, 500);
- szTemp[500] = 0;
- db_free(&dbv);
- title.insert(tempmark + 2, szTemp);
- }
- else p = xStatusDescr[xStatus - 1];
+ ptrT szXStatus(db_get_tsa(dat->hContact, dat->szProto, "XStatusName"));
+ dest.Append((szXStatus != NULL) ? Trunc500(szXStatus) : xStatusDescr[xStatus - 1]);
}
- else p = (TCHAR*)(dat->szStatus && dat->szStatus[0] ? dat->szStatus : _T("(undef)"));
-
- if (p) {
- title.insert(tempmark + 2, p);
- curpos = tempmark + mir_tstrlen(p);
- }
-
- title.erase(tempmark, 2);
+ else dest.Append(dat->szStatus && dat->szStatus[0] ? dat->szStatus : _T("(undef)"));
}
break;
@@ -388,26 +340,24 @@ TCHAR* Utils::FormatTitleBar(const TWindowData *dat, const TCHAR *szFormat)
case 'T':
{
ptrT tszStatus(dat->cache->getNormalizedStatusMsg(dat->cache->getStatusMsg(), true));
- if (tszStatus) {
- title.insert(tempmark + 2, tszStatus);
- curpos = tempmark + mir_tstrlen(tszStatus);
- }
- else if (title[curpos] == 't') {
- p = TranslateT("No status message");
- title.insert(tempmark + 2, p);
- curpos = tempmark + mir_tstrlen(p);
- }
+ if (tszStatus)
+ dest.Append(tszStatus);
+ else if (*src == 't')
+ dest.Append(TranslateT("No status message"));
}
- title.erase(tempmark, 2);
break;
- default:
- title.erase(tempmark, 1);
+ case 'g':
+ {
+ ptrT tszGroup(db_get_tsa(dat->hContact, "CList", "Group"));
+ if (tszGroup != NULL)
+ dest.Append(tszGroup);
+ }
break;
}
}
- return mir_tstrndup(title.c_str(), title.length());
+ return true;
}
char* Utils::FilterEventMarkers(char *szText)
diff --git a/plugins/TabSRMM/src/utils.h b/plugins/TabSRMM/src/utils.h
index 6db72b6c26..878c00fe33 100644
--- a/plugins/TabSRMM/src/utils.h
+++ b/plugins/TabSRMM/src/utils.h
@@ -56,7 +56,7 @@ public:
static TCHAR* GetPreviewWithEllipsis(TCHAR *szText, size_t iMaxLen);
static TCHAR* FilterEventMarkers(TCHAR *wszText);
static LPCTSTR FormatRaw(TWindowData *dat, const TCHAR *msg, int flags, BOOL isSent);
- static LPTSTR FormatTitleBar(const TWindowData *dat, const TCHAR *szFormat);
+ static bool FormatTitleBar(const TWindowData *dat, const TCHAR *szFormat, CMString &dest);
static char* FilterEventMarkers(char *szText);
static LPCTSTR DoubleAmpersands(TCHAR *pszText);
static void RTF_CTableInit();
@@ -68,7 +68,7 @@ public:
static void ReadPrivateContainerSettings(TContainerData *pContainer, bool fForce = false);
static void SaveContainerSettings(TContainerData *pContainer, const char *szSetting);
- static DWORD CALLBACK StreamOut(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG * pcb);
+ static DWORD CALLBACK StreamOut(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG * pcb);
static LRESULT CmdDispatcher(UINT uType, HWND hwndDlg, UINT cmd, WPARAM wParam, LPARAM lParam, TWindowData *dat = 0, TContainerData *pContainer = 0);
static void addMenuItem(const HMENU& m, MENUITEMINFO& mii, HICON hIcon, const TCHAR *szText, UINT uID, UINT pos);