summaryrefslogtreecommitdiff
path: root/plugins/NewXstatusNotify/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/NewXstatusNotify/src/main.cpp')
-rw-r--r--plugins/NewXstatusNotify/src/main.cpp148
1 files changed, 81 insertions, 67 deletions
diff --git a/plugins/NewXstatusNotify/src/main.cpp b/plugins/NewXstatusNotify/src/main.cpp
index bcdfbaad92..daa4fe4c37 100644
--- a/plugins/NewXstatusNotify/src/main.cpp
+++ b/plugins/NewXstatusNotify/src/main.cpp
@@ -32,6 +32,10 @@ STATUS StatusList[STATUS_COUNT];
HWND SecretWnd;
int hLangpack;
+
+int ContactStatusChanged(MCONTACT hContact, WORD oldStatus,WORD newStatus);
+
+
PLUGININFOEX pluginInfoEx = {
sizeof(PLUGININFOEX),
__PLUGIN_NAME,
@@ -437,6 +441,7 @@ int ProcessStatus(DBCONTACTWRITESETTING *cws, MCONTACT hContact)
return 0;
//If we get here, we have to notify the Hooks.
+ ContactStatusChanged(hContact,oldStatus, newStatus);
NotifyEventHooks(hHookContactStatusChanged, hContact, (LPARAM)MAKELPARAM(oldStatus, newStatus));
return 1;
}
@@ -610,26 +615,7 @@ int StatusModeChanged(WPARAM wParam, LPARAM lParam)
return 0;
}
-void ShowStatusChangePopup(MCONTACT hContact, char *szProto, WORD oldStatus, WORD newStatus)
-{
- TCHAR stzStatusText[MAX_SECONDLINE] = {0};
- WORD myStatus = (WORD)CallProtoService(szProto, PS_GETSTATUS, 0, 0);
-
- POPUPDATAT ppd = {0};
- ppd.lchContact = hContact;
- ppd.lchIcon = LoadSkinnedProtoIcon(szProto, newStatus);
- _tcsncpy(ppd.lptzContactName, (TCHAR *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, hContact, GSMDF_TCHAR), MAX_CONTACTNAME);
-
- if (opt.ShowGroup) { //add group name to popup title
- DBVARIANT dbv;
- if (!db_get_ts(hContact, "CList", "Group", &dbv)) {
- _tcscat(ppd.lptzContactName, _T(" ("));
- _tcscat(ppd.lptzContactName, dbv.ptszVal);
- _tcscat(ppd.lptzContactName, _T(")"));
- db_free(&dbv);
- }
- }
-
+void GetStatusText(MCONTACT hContact, WORD newStatus, WORD oldStatus, TCHAR *stzStatusText) {
if (opt.ShowStatus) {
if (opt.UseAlternativeText) {
switch (GetGender(hContact)) {
@@ -652,11 +638,35 @@ void ShowStatusChangePopup(MCONTACT hContact, char *szProto, WORD oldStatus, WOR
_tcscat(_tcscat(stzStatusText, _T(" ")), buff);
}
}
+}
+
+
+void ShowStatusChangePopup(MCONTACT hContact, char *szProto, WORD oldStatus, WORD newStatus)
+{
+ WORD myStatus = (WORD)CallProtoService(szProto, PS_GETSTATUS, 0, 0);
+
+ POPUPDATAT ppd = {0};
+ ppd.lchContact = hContact;
+ ppd.lchIcon = LoadSkinnedProtoIcon(szProto, newStatus);
+ _tcsncpy(ppd.lptzContactName, (TCHAR *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, hContact, GSMDF_TCHAR), MAX_CONTACTNAME);
+
+ if (opt.ShowGroup) { //add group name to popup title
+ DBVARIANT dbv;
+ if (!db_get_ts(hContact, "CList", "Group", &dbv)) {
+ _tcsncat(ppd.lptzContactName, _T(" ("), MAX_CONTACTNAME);
+ _tcsncat(ppd.lptzContactName, dbv.ptszVal, MAX_CONTACTNAME);
+ _tcsncat(ppd.lptzContactName, _T(")"), MAX_CONTACTNAME);
+ db_free(&dbv);
+ }
+ }
+
+ TCHAR stzStatusText[MAX_SECONDLINE] = {0};
+ GetStatusText(hContact,newStatus,oldStatus,stzStatusText);
if (opt.ReadAwayMsg && myStatus != ID_STATUS_INVISIBLE && StatusHasAwayMessage(szProto, newStatus))
db_set_ws(hContact, MODULE, "LastPopupText", stzStatusText);
- _tcscpy(ppd.lptzText, stzStatusText);
+ _tcsncpy(ppd.lptzText, stzStatusText, MAX_SECONDLINE);
switch (opt.Colors) {
case POPUP_COLOR_OWN:
@@ -697,8 +707,8 @@ void BlinkIcon(MCONTACT hContact, char* szProto, WORD status)
cle.pszService = "UserOnline/Description";
cle.ptszTooltip = stzTooltip;
- TCHAR *hlpName = (TCHAR *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, hContact, GCDNF_TCHAR);
- mir_sntprintf(stzTooltip, SIZEOF(stzTooltip), TranslateT("%s is now %s"), hlpName, StatusList[Index(status)].lpzStandardText);
+ mir_sntprintf(stzTooltip, SIZEOF(stzTooltip), TranslateT("%s is now %s"),
+ CallService(MS_CLIST_GETCONTACTDISPLAYNAME, hContact, GCDNF_TCHAR), StatusList[Index(status)].lpzStandardText);
CallService(MS_CLIST_ADDEVENT, 0, (LPARAM)&cle);
}
@@ -725,39 +735,20 @@ void PlayChangeSound(MCONTACT hContact, WORD oldStatus, WORD newStatus)
}
}
- char szSoundFile[MAX_PATH] = {0};
-
- if (!db_get_b(0, "SkinSoundsOff", "UserFromOffline", 0) &&
- !db_get_s(0,"SkinSounds", "UserFromOffline", &dbv) &&
- oldStatus == ID_STATUS_OFFLINE)
- {
- strcpy(szSoundFile, "UserFromOffline");
- db_free(&dbv);
- }
- else if (!db_get_b(0, "SkinSoundsOff", StatusList[Index(newStatus)].lpzSkinSoundName, 0) &&
- !db_get(0, "SkinSounds", StatusList[Index(newStatus)].lpzSkinSoundName, &dbv))
- {
- strcpy(szSoundFile, StatusList[Index(newStatus)].lpzSkinSoundName);
- db_free(&dbv);
- }
-
- if (szSoundFile[0])
- SkinPlaySound(szSoundFile);
+ if (!db_get_b(0, "SkinSoundsOff", "UserFromOffline", 0) && oldStatus == ID_STATUS_OFFLINE)
+ SkinPlaySound("UserFromOffline");
+ else if (!db_get_b(0, "SkinSoundsOff", StatusList[Index(newStatus)].lpzSkinSoundName, 0))
+ SkinPlaySound(StatusList[Index(newStatus)].lpzSkinSoundName);
}
-int ContactStatusChanged(WPARAM hContact, LPARAM lParam)
+int ContactStatusChanged(MCONTACT hContact, WORD oldStatus,WORD newStatus)
{
- WORD oldStatus = LOWORD(lParam);
- WORD newStatus = HIWORD(lParam);
-
bool bEnablePopup = true, bEnableSound = true;
- char *hlpProto = GetContactProto(hContact);
- if (hlpProto == NULL || opt.TempDisabled)
+ char *szProto = GetContactProto(hContact);
+ if (szProto == NULL || opt.TempDisabled)
return 0;
- char szProto[64];
- strcpy(szProto, hlpProto);
WORD myStatus = (WORD)CallProtoService(szProto, PS_GETSTATUS, 0, 0);
if (opt.EnableLastSeen && newStatus == ID_STATUS_OFFLINE && oldStatus > ID_STATUS_OFFLINE) {
@@ -776,13 +767,10 @@ int ContactStatusChanged(WPARAM hContact, LPARAM lParam)
if (!strcmp(szProto, META_PROTO)) { //this contact is Meta
MCONTACT hSubContact = (MCONTACT)CallService(MS_MC_GETMOSTONLINECONTACT, hContact, 0);
- hlpProto = GetContactProto(hSubContact);
- if (hlpProto == NULL)
+ char *szSubProto = GetContactProto(hSubContact);
+ if (szSubProto == NULL)
return 0;
- char szSubProto[64];
- strcpy(szSubProto, hlpProto);
-
if (newStatus == ID_STATUS_OFFLINE) {
// read last online proto for metaconatct if exists,
// to avoid notifying when meta went offline but default contact's proto still online
@@ -797,7 +785,7 @@ int ContactStatusChanged(WPARAM hContact, LPARAM lParam)
if (!db_get_b(0, MODULE, szSubProto, 1))
return 0;
- strcpy(szProto, szSubProto);
+ szProto = szSubProto;
}
else {
if (myStatus == ID_STATUS_OFFLINE || !db_get_b(0, MODULE, szProto, 1))
@@ -836,17 +824,32 @@ int ContactStatusChanged(WPARAM hContact, LPARAM lParam)
if (bEnableSound && db_get_b(0, "Skin", "UseSound", TRUE) && db_get_b(hContact, MODULE, "EnableSounds", 1))
PlayChangeSound(hContact, oldStatus, newStatus);
+ if(opt.LogToDB && (!opt.CheckMessageWindow || CheckMsgWnd(hContact))) {
+ TCHAR stzStatusText[MAX_SECONDLINE] = {0};
+ GetStatusText(hContact,newStatus,oldStatus,stzStatusText);
+ char *blob = mir_utf8encodeT(stzStatusText);
+
+ DBEVENTINFO dbei = {0};
+ dbei.cbSize = sizeof(dbei);
+ dbei.cbBlob = (DWORD)strlen(blob) + 1;
+ dbei.pBlob = (PBYTE) blob;
+ dbei.eventType = EVENTTYPE_STATUSCHANGE;
+ dbei.flags = DBEF_READ | DBEF_UTF;
+
+ dbei.timestamp = (DWORD)time(NULL);
+ dbei.szModule = szProto;
+ HANDLE hDBEvent = db_event_add(hContact, &dbei);
+ mir_free(blob);
+ }
+
if (opt.Log) {
- TCHAR stzName[64], stzStatus[MAX_STATUSTEXT], stzOldStatus[MAX_STATUSTEXT];
- TCHAR stzDate[MAX_STATUSTEXT], stzTime[MAX_STATUSTEXT];
- TCHAR stzText[1024];
+ TCHAR stzDate[MAX_STATUSTEXT], stzTime[MAX_STATUSTEXT], stzText[1024];
- _tcscpy(stzName, (TCHAR *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, hContact, GCDNF_TCHAR));
- _tcsncpy(stzStatus, StatusList[Index(newStatus)].lpzStandardText, MAX_STATUSTEXT);
- _tcsncpy(stzOldStatus, StatusList[Index(oldStatus)].lpzStandardText, MAX_STATUSTEXT);
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 to: %s (was: %s).\r\n"), stzDate, stzTime, stzName, stzStatus, stzOldStatus);
+ mir_sntprintf(stzText, SIZEOF(stzText), TranslateT("%s, %s. %s changed to: %s (was: %s).\r\n"),
+ stzDate, stzTime, CallService(MS_CLIST_GETCONTACTDISPLAYNAME, hContact, GCDNF_TCHAR), StatusList[Index(newStatus)].lpzStandardText,
+ StatusList[Index(oldStatus)].lpzStandardText);
LogToFile(stzText);
}
@@ -1076,8 +1079,6 @@ void InitMainMenuItem()
opt.TempDisabled = !opt.TempDisabled;
EnableDisableMenuCommand(0, 0);
-
- hServiceMenu = (HANDLE)CreateServiceFunction(MS_STATUSCHANGE_MENUCOMMAND, EnableDisableMenuCommand);
}
static IconItem iconList[] =
@@ -1108,8 +1109,8 @@ int InitTopToolbar(WPARAM, LPARAM)
tbb.pszService = MS_STATUSCHANGE_MENUCOMMAND;
tbb.dwFlags = (opt.TempDisabled ? 0 : TTBBF_PUSHED) | TTBBF_ASPUSHBUTTON;
tbb.name = LPGEN("Toggle status notification");
- tbb.hIconHandleUp = GetIconHandle(ICO_NOTIFICATION_OFF);
- tbb.hIconHandleDn = GetIconHandle(ICO_NOTIFICATION_ON);
+ tbb.hIconHandleUp = iconList[0].hIcolib;
+ tbb.hIconHandleDn = iconList[1].hIcolib;
tbb.pszTooltipUp = LPGEN("Enable status notification");
tbb.pszTooltipDn = LPGEN("Disable status notification");
hToolbarButton = TopToolbar_AddButton(&tbb);
@@ -1122,7 +1123,6 @@ int ModulesLoaded(WPARAM wParam, LPARAM lParam)
InitMainMenuItem();
HookEvent(ME_USERINFO_INITIALISE, UserInfoInitialise);
- HookEvent(ME_STATUSCHANGE_CONTACTSTATUSCHANGED, ContactStatusChanged);
HookEvent(ME_MSG_WINDOWEVENT, OnWindowEvent);
HookEvent(ME_TTB_MODULELOADED, InitTopToolbar);
@@ -1169,6 +1169,20 @@ extern "C" int __declspec(dllexport) Load(void)
db_set_resident("MetaContacts", "LastOnline");
db_set_resident("NewStatusNotify", "LastPopupText");
+
+ // register special type of event
+ // there's no need to declare the special service for getting text
+ // because a blob contains only text
+ DBEVENTTYPEDESCR evtype = { sizeof(evtype) };
+ evtype.module = MODULE;
+ evtype.eventType = EVENTTYPE_STATUSCHANGE;
+ evtype.descr = LPGEN("Status change");
+ evtype.eventIcon = iconList[0].hIcolib;
+ evtype.flags = DETF_HISTORY | DETF_MSGWINDOW;
+ CallService(MS_DB_EVENT_REGISTERTYPE, 0, (LPARAM)&evtype);
+
+ hServiceMenu = CreateServiceFunction(MS_STATUSCHANGE_MENUCOMMAND, EnableDisableMenuCommand);
+
return 0;
}