diff options
author | Kirill Volinsky <mataes2007@gmail.com> | 2015-04-06 08:57:39 +0000 |
---|---|---|
committer | Kirill Volinsky <mataes2007@gmail.com> | 2015-04-06 08:57:39 +0000 |
commit | 925a58a69d336f2535a1083ca05cb454e755e226 (patch) | |
tree | 511d3fa9c2d2bb6b585a7af2b4665f3b4017b8a2 /protocols/SkypeWeb/src/skype_avatars.cpp | |
parent | 0cd6f180701a35abe5da0f4b0272b3047c03e330 (diff) |
avatar support 1st attempt
git-svn-id: http://svn.miranda-ng.org/main/trunk@12623 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/SkypeWeb/src/skype_avatars.cpp')
-rw-r--r-- | protocols/SkypeWeb/src/skype_avatars.cpp | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/protocols/SkypeWeb/src/skype_avatars.cpp b/protocols/SkypeWeb/src/skype_avatars.cpp new file mode 100644 index 0000000000..b997c92bb1 --- /dev/null +++ b/protocols/SkypeWeb/src/skype_avatars.cpp @@ -0,0 +1,98 @@ +#include "common.h"
+
+void CSkypeProto::ReloadAvatarInfo(MCONTACT hContact)
+{
+ if (!hContact) {
+ CallService(MS_AV_REPORTMYAVATARCHANGED, (WPARAM)m_szModuleName, 0);
+ return;
+ }
+ PROTO_AVATAR_INFORMATIONT AI = { sizeof(AI) };
+ AI.hContact = hContact;
+ SvcGetAvatarInfo(0, (LPARAM)&AI);
+}
+
+void CSkypeProto::OnReceiveAvatar(const NETLIBHTTPREQUEST *response, void *arg)
+{
+ MCONTACT hContact = (MCONTACT)arg;
+ if (response->resultCode != 200)
+ return;
+
+ PROTO_AVATAR_INFORMATIONT AI = { sizeof(AI) };
+ GetAvatarFileName(hContact, AI.filename, SIZEOF(AI.filename));
+ AI.format = ProtoGetBufferFormat(response->pData);
+
+ FILE *out = _tfopen(AI.filename, _T("wb"));
+ if (out == NULL) {
+ ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_FAILED, &AI, 0);
+ return;
+ }
+
+ fwrite(response->pData, 1, response->dataLength, out);
+ fclose(out);
+ setByte(hContact, "NeedNewAvatar", 0);
+ ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, &AI, 0);
+}
+
+INT_PTR CSkypeProto::SvcGetAvatarInfo(WPARAM, LPARAM lParam)
+{
+ PROTO_AVATAR_INFORMATIONT* AI = (PROTO_AVATAR_INFORMATIONT*)lParam;
+
+ ptrA szUrl(getStringA(AI->hContact, "AvatarUrl"));
+ if (szUrl == NULL)
+ return GAIR_NOAVATAR;
+
+ TCHAR tszFileName[MAX_PATH];
+ GetAvatarFileName(AI->hContact, tszFileName, SIZEOF(tszFileName));
+ _tcsncpy(AI->filename, tszFileName, SIZEOF(AI->filename));
+
+ AI->format = ProtoGetAvatarFormat(AI->filename);
+
+ if (::_taccess(AI->filename, 0) == 0 && !getBool(AI->hContact, "NeedNewAvatar", 0))
+ return GAIR_SUCCESS;
+
+ if (IsOnline()) {
+ PushRequest(new GetAvatarRequest(szUrl), &CSkypeProto::OnReceiveAvatar, (void*)AI->hContact);
+ debugLogA("Requested to read an avatar from '%s'", szUrl);
+ return GAIR_WAITFOR;
+ }
+
+ debugLogA("No avatar");
+ return GAIR_NOAVATAR;
+}
+
+void CSkypeProto::GetAvatarFileName(MCONTACT hContact, TCHAR* pszDest, size_t cbLen)
+{
+ int tPathLen = mir_sntprintf(pszDest, cbLen, _T("%s\\%S"), VARST(_T("%miranda_avatarcache%")), m_szModuleName);
+
+ DWORD dwAttributes = GetFileAttributes(pszDest);
+ if (dwAttributes == 0xffffffff || (dwAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
+ CreateDirectoryTreeT(pszDest);
+
+ pszDest[tPathLen++] = '\\';
+
+ const TCHAR* szFileType = _T(".jpg");
+ ptrA username(getStringA(hContact, "Skypename"));
+ mir_sntprintf(pszDest + tPathLen, MAX_PATH - tPathLen, _T("%s%s"), _A2T(username), szFileType);
+}
+
+void CSkypeProto::SetAvatarUrl(MCONTACT hContact, CMString &tszUrl)
+{
+ CMString oldUrl(getTStringA(hContact, "AvatarUrl"));
+
+ if (tszUrl == oldUrl)
+ return;
+
+ if (tszUrl.IsEmpty()) {
+ delSetting(hContact, "AvatarUrl");
+ ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, NULL, 0);
+ }
+ else {
+ setTString(hContact, "AvatarUrl", tszUrl.GetBuffer());
+ setByte(hContact,"NeedNewAvatar", 1);
+ PROTO_AVATAR_INFORMATIONT AI = { sizeof(AI) };
+ AI.hContact = hContact;
+ GetAvatarFileName(AI.hContact, AI.filename, SIZEOF(AI.filename));
+ AI.format = ProtoGetAvatarFormat(AI.filename);
+ ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, (HANDLE)&AI, 0);
+ }
+}
\ No newline at end of file |