// 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; }
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; }