diff options
author | George Hazan <george.hazan@gmail.com> | 2015-03-20 22:41:23 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2015-03-20 22:41:23 +0000 |
commit | f01cda3ae486a4046e86ec3c26c2c130dffa349a (patch) | |
tree | ee758743a02bbecd59ea4345da54f527c8f73444 /plugins/NewXstatusNotify | |
parent | c16625bfdc49c39ea6c159a70a87b95bbdc7a6c9 (diff) |
another bunch of shit removed
git-svn-id: http://svn.miranda-ng.org/main/trunk@12459 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/NewXstatusNotify')
-rw-r--r-- | plugins/NewXstatusNotify/src/common.h | 1 | ||||
-rw-r--r-- | plugins/NewXstatusNotify/src/main.cpp | 28 | ||||
-rw-r--r-- | plugins/NewXstatusNotify/src/popup.cpp | 4 | ||||
-rw-r--r-- | plugins/NewXstatusNotify/src/popup.h | 2 | ||||
-rw-r--r-- | plugins/NewXstatusNotify/src/utils.cpp | 42 | ||||
-rw-r--r-- | plugins/NewXstatusNotify/src/utils.h | 3 | ||||
-rw-r--r-- | plugins/NewXstatusNotify/src/version.h | 2 | ||||
-rw-r--r-- | plugins/NewXstatusNotify/src/xstatus.cpp | 65 |
8 files changed, 55 insertions, 92 deletions
diff --git a/plugins/NewXstatusNotify/src/common.h b/plugins/NewXstatusNotify/src/common.h index 77af3b76f0..d481072d6a 100644 --- a/plugins/NewXstatusNotify/src/common.h +++ b/plugins/NewXstatusNotify/src/common.h @@ -57,6 +57,7 @@ #include <m_xstatus.h>
#include <m_extraicons.h>
#include <m_string.h>
+#include <m_clistint.h>
#include <m_metacontacts.h>
#include <m_toptoolbar.h>
diff --git a/plugins/NewXstatusNotify/src/main.cpp b/plugins/NewXstatusNotify/src/main.cpp index 3cab47ec08..20c895628f 100644 --- a/plugins/NewXstatusNotify/src/main.cpp +++ b/plugins/NewXstatusNotify/src/main.cpp @@ -21,6 +21,8 @@ #include "common.h"
+CLIST_INTERFACE *pcli;
+
HINSTANCE hInst;
LIST<DBEVENT> eventListXStatus(10);
@@ -112,10 +114,10 @@ static int CompareStatusMsg(STATUSMSGINFO *smi, DBCONTACTWRITESETTING *cws_new, switch (cws_new->value.type) {
case DBVT_ASCIIZ:
- smi->newstatusmsg = (CheckStr(cws_new->value.pszVal, 0, 1) ? NULL : mir_dupToUnicodeEx(cws_new->value.pszVal, CP_ACP));
+ smi->newstatusmsg = (CheckStr(cws_new->value.pszVal, 0, 1) ? NULL : mir_a2t_cp(cws_new->value.pszVal, CP_ACP));
break;
case DBVT_UTF8:
- smi->newstatusmsg = (CheckStr(cws_new->value.pszVal, 0, 1) ? NULL : mir_dupToUnicodeEx(cws_new->value.pszVal, CP_UTF8));
+ smi->newstatusmsg = (CheckStr(cws_new->value.pszVal, 0, 1) ? NULL : mir_a2t_cp(cws_new->value.pszVal, CP_UTF8));
break;
case DBVT_WCHAR:
smi->newstatusmsg = (CheckStrW(cws_new->value.pwszVal, 0, 1) ? NULL : mir_wstrdup(cws_new->value.pwszVal));
@@ -129,10 +131,10 @@ static int CompareStatusMsg(STATUSMSGINFO *smi, DBCONTACTWRITESETTING *cws_new, if (!db_get_s(smi->hContact, "UserOnline", szSetting, &dbv_old, 0)) {
switch (dbv_old.type) {
case DBVT_ASCIIZ:
- smi->oldstatusmsg = (CheckStr(dbv_old.pszVal, 0, 1) ? NULL : mir_dupToUnicodeEx(dbv_old.pszVal, CP_ACP));
+ smi->oldstatusmsg = (CheckStr(dbv_old.pszVal, 0, 1) ? NULL : mir_a2t_cp(dbv_old.pszVal, CP_ACP));
break;
case DBVT_UTF8:
- smi->oldstatusmsg = (CheckStr(dbv_old.pszVal, 0, 1) ? NULL : mir_dupToUnicodeEx(dbv_old.pszVal, CP_UTF8));
+ smi->oldstatusmsg = (CheckStr(dbv_old.pszVal, 0, 1) ? NULL : mir_a2t_cp(dbv_old.pszVal, CP_UTF8));
break;
case DBVT_WCHAR:
smi->oldstatusmsg = (CheckStrW(dbv_old.pwszVal, 0, 1) ? NULL : mir_wstrdup(dbv_old.pwszVal));
@@ -196,21 +198,21 @@ TCHAR* GetStr(STATUSMSGINFO *n, const TCHAR *tmplt) if (n->compare == COMPARE_DEL || mir_tstrcmp(n->newstatusmsg, TranslateT("<no status message>")) == 0)
res.Append(TranslateT("<no status message>"));
else
- res.Append(ptrT(AddCR(n->newstatusmsg)));
+ AddCR(res, n->newstatusmsg);
break;
case 'o':
if (n->oldstatusmsg == NULL || n->oldstatusmsg[0] == _T('\0') || _tcscmp(n->oldstatusmsg, TranslateT("<no status message>")) == 0)
res.Append(TranslateT("<no status message>"));
else
- res.Append(ptrT(AddCR(n->oldstatusmsg)));
+ AddCR(res, n->oldstatusmsg);
break;
case 'c':
if (n->hContact == NULL)
res.Append(TranslateT("Contact"));
else
- res.Append((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)n->hContact, GCDNF_TCHAR));
+ res.Append(pcli->pfnGetContactDisplayName(n->hContact, 0));
break;
case 's':
@@ -445,8 +447,7 @@ int ContactStatusChanged(MCONTACT hContact, WORD oldStatus, WORD newStatus) if (opt.BlinkIcon && !opt.TempDisabled) {
HICON hIcon = opt.BlinkIcon_Status ? LoadSkinnedProtoIcon(szProto, newStatus) : LoadSkinnedIcon(SKINICON_OTHER_USERONLINE);
TCHAR str[256];
- mir_sntprintf(str, SIZEOF(str), TranslateT("%s is now %s"),
- CallService(MS_CLIST_GETCONTACTDISPLAYNAME, hContact, GCDNF_TCHAR), StatusList[Index(newStatus)].lpzStandardText);
+ mir_sntprintf(str, SIZEOF(str), TranslateT("%s is now %s"), pcli->pfnGetContactDisplayName(hContact, 0), StatusList[Index(newStatus)].lpzStandardText);
BlinkIcon(hContact, hIcon, str);
}
@@ -463,7 +464,7 @@ int ContactStatusChanged(MCONTACT hContact, WORD oldStatus, WORD newStatus) GetTimeFormat(LOCALE_USER_DEFAULT, 0, NULL, _T("HH':'mm"), stzTime, SIZEOF(stzTime));
GetDateFormat(LOCALE_USER_DEFAULT, 0, NULL, _T("dd/MM/yyyy"), stzDate, SIZEOF(stzDate));
mir_sntprintf(stzText, SIZEOF(stzText), TranslateT("%s, %s. %s changed status to %s (was %s)\r\n"),
- stzDate, stzTime, CallService(MS_CLIST_GETCONTACTDISPLAYNAME, hContact, GCDNF_TCHAR), StatusList[Index(newStatus)].lpzStandardText,
+ stzDate, stzTime, pcli->pfnGetContactDisplayName(hContact, 0), StatusList[Index(newStatus)].lpzStandardText,
StatusList[Index(oldStatus)].lpzStandardText);
LogToFile(stzText);
}
@@ -736,8 +737,7 @@ int ProcessStatusMessage(DBCONTACTWRITESETTING *cws, MCONTACT hContact) if (opt.BlinkIcon && opt.BlinkIcon_ForMsgs && !opt.TempDisabled) {
HICON hIcon = opt.BlinkIcon_Status ? LoadSkinnedProtoIcon(szProto, db_get_w(hContact, szProto, "Status", ID_STATUS_ONLINE)) : LoadSkinnedIcon(SKINICON_OTHER_USERONLINE);
TCHAR str[256];
- mir_sntprintf(str, SIZEOF(str), TranslateT("%s changed status message to %s"),
- CallService(MS_CLIST_GETCONTACTDISPLAYNAME, hContact, GCDNF_TCHAR), smi.newstatusmsg);
+ mir_sntprintf(str, SIZEOF(str), TranslateT("%s changed status message to %s"), pcli->pfnGetContactDisplayName(hContact, 0), smi.newstatusmsg);
BlinkIcon(hContact, hIcon, str);
}
@@ -764,8 +764,7 @@ int ProcessStatusMessage(DBCONTACTWRITESETTING *cws, MCONTACT hContact) else
str = GetStr(&smi, templates.LogSMsgChanged);
- mir_sntprintf(stzText, SIZEOF(stzText), _T("%s, %s. %s %s\r\n"), stzDate, stzTime,
- CallService(MS_CLIST_GETCONTACTDISPLAYNAME, hContact, GCDNF_TCHAR), str);
+ mir_sntprintf(stzText, SIZEOF(stzText), _T("%s, %s. %s %s\r\n"), stzDate, stzTime, pcli->pfnGetContactDisplayName(hContact, 0), str);
LogToFile(stzText);
mir_free(str);
@@ -1161,6 +1160,7 @@ static int OnShutdown(WPARAM, LPARAM) extern "C" int __declspec(dllexport) Load(void)
{
mir_getLP(&pluginInfoEx);
+ mir_getCLI();
//"Service" Hook, used when the DB settings change: we'll monitor the "status" setting.
HookEvent(ME_DB_CONTACT_SETTINGCHANGED, ContactSettingChanged);
diff --git a/plugins/NewXstatusNotify/src/popup.cpp b/plugins/NewXstatusNotify/src/popup.cpp index 2e37d89fa9..8410aea172 100644 --- a/plugins/NewXstatusNotify/src/popup.cpp +++ b/plugins/NewXstatusNotify/src/popup.cpp @@ -21,12 +21,12 @@ #include "common.h"
-void ShowChangePopup(MCONTACT hContact, HICON hIcon, WORD newStatus, TCHAR *stzText, PLUGINDATA *pdp)
+void ShowChangePopup(MCONTACT hContact, HICON hIcon, WORD newStatus, const TCHAR *stzText, PLUGINDATA *pdp)
{
POPUPDATAT ppd = { 0 };
ppd.lchContact = hContact;
ppd.lchIcon = hIcon;
- CMString buf((TCHAR *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, hContact, GSMDF_TCHAR));
+ CMString buf(pcli->pfnGetContactDisplayName(hContact, 0));
// add group name to popup title
if (opt.ShowGroup) {
diff --git a/plugins/NewXstatusNotify/src/popup.h b/plugins/NewXstatusNotify/src/popup.h index fd550392a2..5bcce77072 100644 --- a/plugins/NewXstatusNotify/src/popup.h +++ b/plugins/NewXstatusNotify/src/popup.h @@ -58,7 +58,7 @@ static struct { LPGENT("Do nothing"), PCA_DONOTHING
};
-void ShowChangePopup(MCONTACT hContact, HICON hIcon, WORD newStatus, TCHAR *stzText, PLUGINDATA *pdp = NULL);
+void ShowChangePopup(MCONTACT hContact, HICON hIcon, WORD newStatus, const TCHAR *stzText, PLUGINDATA *pdp = NULL);
LRESULT CALLBACK PopupDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
#endif
\ No newline at end of file diff --git a/plugins/NewXstatusNotify/src/utils.cpp b/plugins/NewXstatusNotify/src/utils.cpp index c41da2cd63..951a2dd551 100644 --- a/plugins/NewXstatusNotify/src/utils.cpp +++ b/plugins/NewXstatusNotify/src/utils.cpp @@ -96,39 +96,13 @@ void LogToFile(TCHAR *stzText) }
}
-WCHAR *mir_dupToUnicodeEx(char *ptr, UINT CodePage)
+void AddCR(CMString &str, const TCHAR *stzText)
{
- if (ptr == NULL)
- return NULL;
-
- size_t size = strlen(ptr) + 1;
- WCHAR *tmp = (WCHAR *)mir_alloc(size * sizeof(WCHAR));
-
- MultiByteToWideChar(CodePage, 0, ptr, -1, tmp, (int)size * sizeof(WCHAR));
- return tmp;
-}
-
-TCHAR *AddCR(const TCHAR *stzText)
-{
- const TCHAR *found;
- size_t i = 0, len = mir_tstrlen(stzText), j;
- TCHAR *tmp = (TCHAR *)mir_alloc(1024 * sizeof(TCHAR));
- *tmp = _T('\0');
- while ((found = _tcsstr((stzText + i), _T("\n"))) != NULL && _tcslen(tmp) + 1 < 1024) {
- j = (int)(found - stzText);
- if (mir_tstrlen(tmp) + j - i + 2 < 1024)
- tmp = mir_tstrcat(tmp, stzText + i);
- else
- break;
-
- if (j == 0 || *(stzText + j - 1) != _T('\r'))
- tmp = mir_tstrcat(tmp, _T("\r"));
-
- tmp = mir_tstrcat(tmp, _T("\n"));
- i = j + 1;
- }
- if (mir_tstrlen(tmp) + len - i + 1 < 1024)
- tmp = mir_tstrcat(tmp, stzText + i);
-
- return tmp;
+ if (stzText == NULL)
+ return;
+
+ CMString res(stzText);
+ res.Replace(_T("\n"), _T("\r\n"));
+ res.Replace(_T("\r\r\n"), _T("\r\n"));
+ str.Append(res);
}
diff --git a/plugins/NewXstatusNotify/src/utils.h b/plugins/NewXstatusNotify/src/utils.h index 1f5838b288..d7496edf30 100644 --- a/plugins/NewXstatusNotify/src/utils.h +++ b/plugins/NewXstatusNotify/src/utils.h @@ -27,7 +27,6 @@ int DBGetStringDefault(MCONTACT hContact, const char *szModule, const char *szSe void ShowLog(TCHAR *file);
BOOL StatusHasAwayMessage(char *szProto, int status);
void LogToFile(TCHAR *stzText);
-WCHAR *mir_dupToUnicodeEx(char *ptr, UINT CodePage);
-TCHAR *AddCR(const TCHAR *statusmsg);
+void AddCR(CMString &str, const TCHAR *statusmsg);
#endif
diff --git a/plugins/NewXstatusNotify/src/version.h b/plugins/NewXstatusNotify/src/version.h index 1f7c128b06..c630350106 100644 --- a/plugins/NewXstatusNotify/src/version.h +++ b/plugins/NewXstatusNotify/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 1
#define __MINOR_VERSION 4
#define __RELEASE_NUM 0
-#define __BUILD_NUM 10
+#define __BUILD_NUM 11
#include <stdver.h>
diff --git a/plugins/NewXstatusNotify/src/xstatus.cpp b/plugins/NewXstatusNotify/src/xstatus.cpp index 59ade666d2..954623bd94 100644 --- a/plugins/NewXstatusNotify/src/xstatus.cpp +++ b/plugins/NewXstatusNotify/src/xstatus.cpp @@ -76,7 +76,7 @@ void RemoveLoggedEventsSMsg(MCONTACT hContact) }
}
-TCHAR *GetStatusTypeAsString(int type, TCHAR *buff)
+TCHAR* GetStatusTypeAsString(int type, TCHAR *buff)
{
switch (type) {
case TYPE_JABBER_MOOD:
@@ -90,51 +90,47 @@ TCHAR *GetStatusTypeAsString(int type, TCHAR *buff) }
}
-TCHAR *ReplaceVars(XSTATUSCHANGE *xsc, const TCHAR *tmplt)
+CMString ReplaceVars(XSTATUSCHANGE *xsc, const TCHAR *tmplt)
{
if (xsc == NULL || tmplt == NULL || tmplt[0] == _T('\0'))
- return NULL;
+ return CMString();
- TCHAR *str = (TCHAR *)mir_alloc(2048 * sizeof(TCHAR));
- str[0] = _T('\0');
size_t len = mir_tstrlen(tmplt);
+ CMString res;
- TCHAR tmp[1024];
for (size_t i = 0; i < len; i++) {
- tmp[0] = _T('\0');
-
if (tmplt[i] == _T('%')) {
i++;
switch (tmplt[i]) {
case 'n':
TCHAR stzType[32];
- mir_tstrncpy(tmp, GetStatusTypeAsString(xsc->type, stzType), SIZEOF(tmp));
+ res.Append(GetStatusTypeAsString(xsc->type, stzType));
break;
case 't':
if (xsc->stzTitle == NULL || xsc->stzTitle[0] == _T('\0'))
- mir_tstrncpy(tmp, TranslateT("<no title>"), SIZEOF(tmp));
+ res.Append(TranslateT("<no title>"));
else
- mir_tstrncpy(tmp, xsc->stzTitle, SIZEOF(tmp));
+ res.Append(xsc->stzTitle);
break;
case 'm':
if (xsc->stzText == NULL || xsc->stzText[0] == _T('\0'))
- mir_tstrncpy(tmp, TranslateT("<no status message>"), SIZEOF(tmp));
+ res.Append(TranslateT("<no status message>"));
else
- mir_tstrncpy(tmp, ptrT(AddCR(xsc->stzText)), SIZEOF(tmp));
+ AddCR(res, xsc->stzText);
break;
case 'c':
if (xsc->hContact == NULL)
- mir_tstrncpy(tmp, TranslateT("Contact"), SIZEOF(tmp));
+ res.Append(TranslateT("Contact"));
else
- mir_tstrncpy(tmp, (TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)xsc->hContact, GCDNF_TCHAR), SIZEOF(tmp));
+ res.Append(pcli->pfnGetContactDisplayName(xsc->hContact, 0));
break;
default:
i--;
- tmp[0] = tmplt[i], tmp[1] = _T('\0');
+ res.AppendChar(tmplt[i]);
break;
}
}
@@ -142,31 +138,26 @@ TCHAR *ReplaceVars(XSTATUSCHANGE *xsc, const TCHAR *tmplt) i++;
switch (tmplt[i]) {
case 'n':
- tmp[0] = _T('\r'), tmp[1] = _T('\n'), tmp[2] = _T('\0');
+ res.AppendChar('\r'); res.AppendChar('\n');
break;
case 't':
- tmp[0] = _T('\t'), tmp[1] = _T('\0');
+ res.AppendChar('\t');
break;
default:
i--;
- tmp[0] = tmplt[i], tmp[1] = _T('\0');
- break;
- }
- }
- else
- tmp[0] = tmplt[i], tmp[1] = _T('\0');
-
- if (tmp[0] != _T('\0')) {
- if (mir_tstrlen(tmp) + mir_tstrlen(str) < 2044)
- mir_tstrcat(str, tmp);
- else {
- mir_tstrcat(str, _T("..."));
+ res.AppendChar(tmplt[i]);
break;
}
}
+ else res.AppendChar(tmplt[i]);
}
- return str;
+ if (res.GetLength() > 2044) {
+ res.Truncate(2044);
+ res.Append(_T("..."));
+ }
+
+ return res;
}
void ShowXStatusPopup(XSTATUSCHANGE *xsc)
@@ -219,7 +210,7 @@ void ShowXStatusPopup(XSTATUSCHANGE *xsc) Template = templates.PopupXMsgRemoved; break;
}
- ShowChangePopup(xsc->hContact, hIcon, ID_STATUS_EXTRASTATUS, ptrT(ReplaceVars(xsc, Template)));
+ ShowChangePopup(xsc->hContact, hIcon, ID_STATUS_EXTRASTATUS, ReplaceVars(xsc, Template));
if (copyText) {
mir_free(xsc->stzText);
@@ -235,7 +226,7 @@ void BlinkXStatusIcon(XSTATUSCHANGE *xsc) HICON hIcon = NULL;
TCHAR str[256] = { 0 };
TCHAR stzType[32];
- mir_sntprintf(str, SIZEOF(str), TranslateT("%s changed %s"), CallService(MS_CLIST_GETCONTACTDISPLAYNAME, xsc->hContact, GCDNF_TCHAR), GetStatusTypeAsString(xsc->type, stzType));
+ mir_sntprintf(str, SIZEOF(str), TranslateT("%s changed %s"), pcli->pfnGetContactDisplayName(xsc->hContact, 0), GetStatusTypeAsString(xsc->type, stzType));
if (opt.BlinkIcon_Status) {
DBVARIANT dbv;
@@ -297,7 +288,7 @@ void LogChangeToDB(XSTATUSCHANGE *xsc) }
TCHAR stzLastLog[2 * MAX_TEXT_LEN];
- ptrT stzLogText(ReplaceVars(xsc, Template));
+ CMString stzLogText(ReplaceVars(xsc, Template));
DBGetStringDefault(xsc->hContact, MODULE, DB_LASTLOG, stzLastLog, SIZEOF(stzLastLog), _T(""));
if (opt.XLogToDB) {
@@ -346,12 +337,10 @@ void LogChangeToFile(XSTATUSCHANGE *xsc) Template = templates.LogXMsgRemoved; break;
}
- TCHAR *stzLogText = ReplaceVars(xsc, Template);
-
- mir_sntprintf(stzText, SIZEOF(stzText), _T("%s, %s. %s %s\r\n"), stzDate, stzTime, CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)xsc->hContact, GCDNF_TCHAR), stzLogText);
+ mir_sntprintf(stzText, SIZEOF(stzText), _T("%s, %s. %s %s\r\n"), stzDate, stzTime,
+ pcli->pfnGetContactDisplayName(xsc->hContact, 0), ReplaceVars(xsc, Template).GetString());
LogToFile(stzText);
- mir_free(stzLogText);
}
void ExtraStatusChanged(XSTATUSCHANGE *xsc)
|