static INT_PTR IsEnabled(WPARAM wParam, LPARAM lParam) { HANDLE hContact = (HANDLE) wParam; return ContactEnabled(hContact, "LogToDisk", AVH_DEF_LOGTODISK) || ContactEnabled(hContact, "AvatarPopups", AVH_DEF_AVPOPUPS) || ContactEnabled(hContact, "LogToHistory", AVH_DEF_LOGTOHISTORY); }
BOOL ContactEnabled(HANDLE hContact) { if (hContact == NULL) return FALSE; char *proto = (char *) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM) hContact, 0); if (!ProtocolEnabled(proto)) return FALSE; BYTE def = TRUE; // Is a subcontact? if (ServiceExists(MS_MC_GETMETACONTACT)) { HANDLE hMetaContact = (HANDLE) CallService(MS_MC_GETMETACONTACT, (WPARAM)hContact, 0); if (hMetaContact != NULL) def = ContactEnabled(hMetaContact); } return DBGetContactSettingByte(hContact, MODULE_NAME, "Enabled", def); }
// fired when the contacts avatar changes // wParam = hContact // lParam = struct avatarCacheEntry *cacheEntry // the event CAN pass a NULL pointer in lParam which means that the avatar has changed, // but is no longer valid (happens, when a contact removes his avatar, for example). // DONT DESTROY the bitmap handle passed in the struct avatarCacheEntry * // // It is also possible that this event passes 0 as wParam (hContact), in which case, // a protocol picture (pseudo - avatar) has been changed. static int AvatarChanged(WPARAM wParam, LPARAM lParam) { HANDLE hContact = (HANDLE)wParam; CONTACTAVATARCHANGEDNOTIFICATION* avatar = (CONTACTAVATARCHANGEDNOTIFICATION*)lParam; if (hContact == NULL) { ShowDebugPopup(NULL, _T("AVH Debug"), _T("Invalid contact/avatar... skipping")); return 0; } char *proto = (char *) CallService(MS_PROTO_GETCONTACTBASEPROTO, wParam, 0); if (proto == NULL) { ShowDebugPopup(hContact, _T("AVH Debug"), _T("Invalid protocol... skipping")); return 0; } else if (metacontacts_proto != NULL && strcmp(metacontacts_proto, proto) == 0) { ShowDebugPopup(hContact, _T("AVH Debug"), _T("Ignoring metacontacts notification")); return 0; } DBVARIANT dbvOldHash = {0}; bool ret = (DBGetContactSettingTString(hContact,MODULE_NAME,"AvatarHash",&dbvOldHash) == 0); if (avatar == NULL) { if (!ret || !_tcscmp(dbvOldHash.ptszVal, _T("-"))) { //avoid duplicate "removed avatar" notifications //do not notify on an empty profile ShowDebugPopup(hContact, _T("AVH Debug"), _T("Removed avatar, no avatar before...skipping")); DBFreeVariant(&dbvOldHash); return 0; } SkinPlaySound("avatar_removed"); // Is a flash avatar or avs could not load it DBWriteContactSettingTString(hContact, MODULE_NAME, "AvatarHash", _T("-")); if (ContactEnabled(hContact, "AvatarPopups", AVH_DEF_AVPOPUPS) && opts.popup_show_removed) ShowPopup(hContact, NULL, opts.popup_removed); if (ContactEnabled(hContact, "LogToHistory", AVH_DEF_LOGTOHISTORY)) HistoryEvents_AddToHistorySimple(hContact, EVENTTYPE_AVATAR_CHANGE, 1, DBEF_READ); } else { if(ret && !_tcscmp(dbvOldHash.ptszVal, avatar->hash)) { // same avatar hash, skipping ShowDebugPopup(hContact, _T("AVH Debug"), _T("Hashes are the same... skipping")); DBFreeVariant(&dbvOldHash); return 0; } SkinPlaySound("avatar_changed"); DBWriteContactSettingTString(hContact, "AvatarHistory", "AvatarHash", avatar->hash); TCHAR history_filename[MAX_PATH] = _T(""); if (ContactEnabled(hContact, "LogToDisk", AVH_DEF_LOGTODISK)) { if (!opts.log_store_as_hash) { if (opts.log_per_contact_folders) { GetOldStyleAvatarName(history_filename, hContact); if (CopyImageFile(avatar->filename, history_filename)) ShowPopup(hContact, _T("Avatar History: Unable to save avatar"), history_filename); else ShowDebugPopup(hContact, _T("AVH Debug: File copied successfully"), history_filename); if (ServiceExists(MS_MC_GETMETACONTACT)) { HANDLE hMetaContact = (HANDLE) CallService(MS_MC_GETMETACONTACT, wParam, 0); if (hMetaContact != NULL && ContactEnabled(hMetaContact, "LogToDisk", AVH_DEF_LOGTOHISTORY)) { TCHAR filename[MAX_PATH] = _T(""); GetOldStyleAvatarName(filename, hMetaContact); if (CopyImageFile(avatar->filename, filename)) ShowPopup(hContact, _T("Avatar History: Unable to save avatar"), filename); else ShowDebugPopup(hContact, _T("AVH Debug: File copied successfully"), filename); } } } } else { // See if we already have the avatar TCHAR hash[128]; lstrcpyn(hash, avatar->hash, sizeof(hash)); ConvertToFilename(hash, sizeof(hash)); TCHAR *file = GetCachedAvatar(proto, hash); if (file != NULL) { lstrcpyn(history_filename, file, MAX_REGS(history_filename)); mir_free(file); } else { if (opts.log_keep_same_folder) GetHistoryFolder(history_filename); else GetProtocolFolder(history_filename, proto); mir_sntprintf(history_filename, MAX_REGS(history_filename), _T("%s\\%s"), history_filename, hash); if (CopyImageFile(avatar->filename, history_filename)) ShowPopup(hContact, _T("Avatar History: Unable to save avatar"), history_filename); else ShowDebugPopup(hContact, _T("AVH Debug: File copied successfully"), history_filename); } if (opts.log_per_contact_folders) { CreateOldStyleShortcut(hContact, history_filename); if (ServiceExists(MS_MC_GETMETACONTACT)) { HANDLE hMetaContact = (HANDLE) CallService(MS_MC_GETMETACONTACT, wParam, 0); if (hMetaContact != NULL && ContactEnabled(hMetaContact, "LogToDisk", AVH_DEF_LOGTOHISTORY)) CreateOldStyleShortcut(hMetaContact, history_filename); } } } } if (ContactEnabled(hContact, "AvatarPopups", AVH_DEF_AVPOPUPS) && opts.popup_show_changed) ShowPopup(hContact, NULL, opts.popup_changed); if (ContactEnabled(hContact, "LogToHistory", AVH_DEF_LOGTOHISTORY)) { TCHAR rel_path[MAX_PATH] = _T(""); CallService(MS_UTILS_PATHTORELATIVET,(WPARAM)history_filename,(LPARAM)rel_path); #ifdef _UNICODE char *blob = mir_utf8encodeT(rel_path); int flags = DBEF_READ | DBEF_UTF; #else char *blob = mir_strdup(rel_path); int flags = DBEF_READ; #endif HistoryEvents_AddToHistoryEx(hContact, EVENTTYPE_AVATAR_CHANGE, 0, NULL, 0, (PBYTE) blob, (int) strlen(blob) + 1, flags); } } return 0; }
int SettingChanged(WPARAM wParam,LPARAM lParam) { if (!loaded) return 0; if (!opts.history_enable && !opts.popup_enable) return 0; HANDLE hContact = (HANDLE) wParam; if (hContact == NULL) return 0; char *proto = (char *) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM) hContact, 0); if (proto == NULL || (metacontacts_proto != NULL && !strcmp(proto, metacontacts_proto))) return 0; DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING*)lParam; if (!strcmp(cws->szModule, proto) && !strcmp(cws->szSetting, "Nick")) { if (opts.track_only_not_offline) { if (DBGetContactSettingWord(hContact, proto, "Status", 0) <= ID_STATUS_OFFLINE) return 0; } if (!ContactEnabled(hContact)) return 0; int changed = TrackChange(hContact, cws, !opts.track_removes); if (changed == 0) return 0; if (changed == 2) { Notify(hContact, NULL); } else // changed == 1 #ifdef UNICODE if (cws->value.type == DBVT_ASCIIZ) { WCHAR tmp[1024] = L""; MultiByteToWideChar(CP_ACP, 0, cws->value.pszVal, -1, tmp, MAX_REGS(tmp)); Notify(hContact, tmp); } else if (cws->value.type == DBVT_UTF8) { WCHAR tmp[1024] = L""; MultiByteToWideChar(CP_UTF8, 0, cws->value.pszVal, -1, tmp, MAX_REGS(tmp)); Notify(hContact, tmp); } else if (cws->value.type == DBVT_WCHAR) { Notify(hContact, cws->value.pwszVal); } #else if (cws->value.type == DBVT_ASCIIZ) { Notify(hContact, cws->value.pszVal); } #endif } return 0; }
HANDLE HistoryLog(HANDLE hContact, TCHAR *log_text) { if (log_text != NULL) { DBEVENTINFO event = { 0 }; BYTE *tmp = NULL; event.cbSize = sizeof(event); #ifdef UNICODE size_t needed = WideCharToMultiByte(CP_ACP, 0, log_text, -1, NULL, 0, NULL, NULL); size_t len = lstrlen(log_text); size_t size; if (opts.history_only_ansi_if_possible && IsUnicodeAscii(log_text, len)) size = needed; else size = needed + (len + 1) * sizeof(WCHAR); tmp = (BYTE *) mir_alloc0(size); WideCharToMultiByte(CP_ACP, 0, log_text, -1, (char *) tmp, needed, NULL, NULL); if (size > needed) lstrcpyn((WCHAR *) &tmp[needed], log_text, len + 1); event.pBlob = tmp; event.cbBlob = size; #else event.pBlob = (PBYTE) log_text; event.cbBlob = strlen(log_text) + 1; #endif event.eventType = EVENTTYPE_NICKNAME_CHANGE; event.flags = DBEF_READ; event.timestamp = (DWORD) time(NULL); event.szModule = MODULE_NAME; // Is a subcontact? if (ServiceExists(MS_MC_GETMETACONTACT)) { HANDLE hMetaContact = (HANDLE) CallService(MS_MC_GETMETACONTACT, (WPARAM)hContact, 0); if (hMetaContact != NULL && ContactEnabled(hMetaContact)) CallService(MS_DB_EVENT_ADD,(WPARAM)hMetaContact,(LPARAM)&event); } HANDLE ret = (HANDLE) CallService(MS_DB_EVENT_ADD,(WPARAM)hContact,(LPARAM)&event); mir_free(tmp); return ret; } else { return NULL; } }
int HistoryEnabled(WPARAM wParam, LPARAM lParam) { return ContactEnabled((HANDLE) wParam); }
static int AvatarChanged(WPARAM hContact, LPARAM lParam) { if (hContact == NULL) return 0; char *proto = GetContactProto(hContact); if (proto == NULL) return 0; if (strcmp(META_PROTO, proto) == 0) return 0; DBVARIANT dbvOldHash = {0}; bool ret = (db_get_ts(hContact,MODULE_NAME,"AvatarHash",&dbvOldHash) == 0); CONTACTAVATARCHANGEDNOTIFICATION* avatar = (CONTACTAVATARCHANGEDNOTIFICATION*)lParam; if (avatar == NULL) { if (!ret || !_tcscmp(dbvOldHash.ptszVal, _T("-"))) { //avoid duplicate "removed avatar" notifications //do not notify on an empty profile ShowDebugPopup(hContact, TranslateT("AVH Debug"), TranslateT("Removed avatar, no avatar before... skipping")); db_free(&dbvOldHash); return 0; } SkinPlaySound("avatar_removed"); // Is a flash avatar or avs could not load it db_set_ts(hContact, MODULE_NAME, "AvatarHash", _T("-")); if (ContactEnabled(hContact, "AvatarPopups", AVH_DEF_AVPOPUPS) && opts.popup_show_removed) ShowPopup(hContact, NULL, opts.popup_removed); } else { if (ret && !_tcscmp(dbvOldHash.ptszVal, avatar->hash)) { // same avatar hash, skipping ShowDebugPopup(hContact, TranslateT("AVH Debug"), TranslateT("Hashes are the same... skipping")); db_free(&dbvOldHash); return 0; } SkinPlaySound("avatar_changed"); db_set_ts(hContact, "AvatarHistory", "AvatarHash", avatar->hash); TCHAR history_filename[MAX_PATH] = _T(""); if (ContactEnabled(hContact, "LogToDisk", AVH_DEF_LOGTODISK)) { if (!opts.log_store_as_hash) { if (opts.log_per_contact_folders) { GetOldStyleAvatarName(history_filename, hContact); if (CopyImageFile(avatar->filename, history_filename)) ShowPopup(hContact, TranslateT("Avatar History: Unable to save avatar"), history_filename); else ShowDebugPopup(hContact, TranslateT("AVH Debug: File copied successfully"), history_filename); MCONTACT hMetaContact = db_mc_getMeta(hContact); if (hMetaContact && ContactEnabled(hMetaContact, "LogToDisk", AVH_DEF_LOGTOHISTORY)) { TCHAR filename[MAX_PATH] = _T(""); GetOldStyleAvatarName(filename, hMetaContact); if (CopyImageFile(avatar->filename, filename)) ShowPopup(hContact, TranslateT("Avatar History: Unable to save avatar"), filename); else ShowDebugPopup(hContact, TranslateT("AVH Debug: File copied successfully"), filename); } } } else { // See if we already have the avatar TCHAR hash[128]; _tcsncpy_s(hash, avatar->hash, _TRUNCATE); ConvertToFilename(hash, SIZEOF(hash)); TCHAR *file = GetCachedAvatar(proto, hash); if (file != NULL) { mir_tstrncpy(history_filename, file, SIZEOF(history_filename)); mir_free(file); } else { if (opts.log_keep_same_folder) GetHistoryFolder(history_filename); else GetProtocolFolder(history_filename, proto); mir_sntprintf(history_filename, SIZEOF(history_filename), _T("%s\\%s"), history_filename, hash); if (CopyImageFile(avatar->filename, history_filename)) ShowPopup(hContact, TranslateT("Avatar History: Unable to save avatar"), history_filename); else ShowDebugPopup(hContact, TranslateT("AVH Debug: File copied successfully"), history_filename); } if (opts.log_per_contact_folders) { CreateOldStyleShortcut(hContact, history_filename); MCONTACT hMetaContact = db_mc_getMeta(hContact); if (hMetaContact && ContactEnabled(hMetaContact, "LogToDisk", AVH_DEF_LOGTOHISTORY)) CreateOldStyleShortcut(hMetaContact, history_filename); } } } if (ContactEnabled(hContact, "AvatarPopups", AVH_DEF_AVPOPUPS) && opts.popup_show_changed) ShowPopup(hContact, NULL, opts.popup_changed); if (ContactEnabled(hContact, "LogToHistory", AVH_DEF_LOGTOHISTORY)) { TCHAR rel_path[MAX_PATH]; PathToRelativeT(history_filename, rel_path); ptrA blob( mir_utf8encodeT(rel_path)); DBEVENTINFO dbei = { sizeof(dbei) }; dbei.szModule = GetContactProto(hContact); dbei.flags = DBEF_READ | DBEF_UTF; dbei.timestamp = (DWORD) time(NULL); dbei.eventType = EVENTTYPE_AVATAR_CHANGE; dbei.cbBlob = (DWORD) strlen(blob) + 1; dbei.pBlob = (PBYTE)(char*)blob; db_event_add(hContact, &dbei); } } return 0; }