summaryrefslogtreecommitdiff
path: root/protocols/Gadu-Gadu/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2013-08-11 10:41:37 +0000
committerGeorge Hazan <george.hazan@gmail.com>2013-08-11 10:41:37 +0000
commit94dcc72f13094157f344f284aec4edf0c0f5faa1 (patch)
tree74c078daadd4abe5aea9e9e0a73b4dd7c4a7fde1 /protocols/Gadu-Gadu/src
parent42ff2169dbddd25d06404623dba2fff222d17c73 (diff)
ProtoGetAvatarFormat, ProtoGetAvatarFileFormat, ProtoGetBufferFormat, ProtoGetAvatarExtension - standard helpers for protocol avatars' processing instead of the zoo that existed previously
git-svn-id: http://svn.miranda-ng.org/main/trunk@5645 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Gadu-Gadu/src')
-rw-r--r--protocols/Gadu-Gadu/src/avatar.cpp13
-rw-r--r--protocols/Gadu-Gadu/src/services.cpp51
2 files changed, 9 insertions, 55 deletions
diff --git a/protocols/Gadu-Gadu/src/avatar.cpp b/protocols/Gadu-Gadu/src/avatar.cpp
index 66a249b92c..9130366d8d 100644
--- a/protocols/Gadu-Gadu/src/avatar.cpp
+++ b/protocols/Gadu-Gadu/src/avatar.cpp
@@ -30,7 +30,6 @@ void GGPROTO::getAvatarFilename(HANDLE hContact, TCHAR *pszDest, int cbLen)
{
int tPathLen;
TCHAR *path = (TCHAR*)alloca(cbLen * sizeof(TCHAR));
- TCHAR *avatartype = NULL;
if (hAvatarsFolder == NULL || FoldersGetCustomPathT(hAvatarsFolder, path, cbLen, _T("")))
tPathLen = mir_sntprintf(pszDest, cbLen, _T("%s\\%S"), VARST( _T("%miranda_avatarcache%")), m_szModuleName);
@@ -51,22 +50,18 @@ void GGPROTO::getAvatarFilename(HANDLE hContact, TCHAR *pszDest, int cbLen)
}
}
- switch (getByte(hContact, GG_KEY_AVATARTYPE, GG_KEYDEF_AVATARTYPE)) {
- case PA_FORMAT_JPEG: avatartype = _T("jpg"); break;
- case PA_FORMAT_GIF: avatartype = _T("gif"); break;
- case PA_FORMAT_PNG: avatartype = _T("png"); break;
- }
+ const TCHAR *avatartype = ProtoGetAvatarExtension( getByte(hContact, GG_KEY_AVATARTYPE, GG_KEYDEF_AVATARTYPE));
if (hContact != NULL) {
DBVARIANT dbv;
if (!getString(hContact, GG_KEY_AVATARHASH, &dbv)) {
TCHAR* avatarHashT = mir_a2t(dbv.pszVal);
- mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, _T("\\%s.%s"), avatarHashT, avatartype);
+ mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, _T("\\%s%s"), avatarHashT, avatartype);
mir_free(avatarHashT);
db_free(&dbv);
}
}
- else mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, _T("\\%S avatar.%s"), m_szModuleName, avatartype);
+ else mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, _T("\\%S avatar%s"), m_szModuleName, avatartype);
}
bool GGPROTO::getAvatarFileInfo(uin_t uin, char **avatarurl, char **avatarts)
@@ -247,7 +242,7 @@ void __cdecl GGPROTO::avatarrequestthread(void*)
for (int i=0; i < resp->headersCount; i++)
{
NETLIBHTTPHEADER& tHeader = resp->headers[i];
- if (!_stricmp(tHeader.szName, "Content-Type")){
+ if (!_stricmp(tHeader.szName, "Content-Type")) {
if (!_stricmp(tHeader.szValue, "image/jpeg"))
avatarType = PA_FORMAT_JPEG;
else if (!_stricmp(tHeader.szValue, "image/gif"))
diff --git a/protocols/Gadu-Gadu/src/services.cpp b/protocols/Gadu-Gadu/src/services.cpp
index adb9e792d6..6fef25e6d9 100644
--- a/protocols/Gadu-Gadu/src/services.cpp
+++ b/protocols/Gadu-Gadu/src/services.cpp
@@ -168,37 +168,6 @@ INT_PTR GGPROTO::getavatarcaps(WPARAM wParam, LPARAM lParam)
return 0;
}
-int GetImageFormat(TCHAR *filename)
-{
- size_t len = lstrlen(filename);
-
- if (len < 5)
- return PA_FORMAT_UNKNOWN;
-
- if (_tcsicmp(_T(".png"), &filename[len-4]) == 0)
- return PA_FORMAT_PNG;
-
- if (_tcsicmp(_T(".jpg"), &filename[len-4]) == 0 || _tcsicmp(_T(".jpeg"), &filename[len-4]) == 0)
- return PA_FORMAT_JPEG;
-
- if (_tcsicmp(_T(".ico"), &filename[len-4]) == 0)
- return PA_FORMAT_ICON;
-
- if (_tcsicmp(_T(".bmp"), &filename[len-4]) == 0 || _tcsicmp(_T(".rle"), &filename[len-4]) == 0)
- return PA_FORMAT_BMP;
-
- if (_tcsicmp(_T(".gif"), &filename[len-4]) == 0)
- return PA_FORMAT_GIF;
-
- if (_tcsicmp(_T(".swf"), &filename[len-4]) == 0)
- return PA_FORMAT_SWF;
-
- if (_tcsicmp(_T(".xml"), &filename[len-4]) == 0)
- return PA_FORMAT_XML;
-
- return PA_FORMAT_UNKNOWN;
-}
-
//////////////////////////////////////////////////////////
// gets avatar information
// registered as ProtoService PS_GETAVATARINFOT
@@ -226,7 +195,7 @@ INT_PTR GGPROTO::getavatarinfo(WPARAM wParam, LPARAM lParam)
if ((_tcslen(dbv.ptszVal)>0) && db_get_b(pai->hContact, "ContactPhoto", "Locked", 0)){
netlog("getavatarinfo(): Incoming request for avatar information. Contact has assigned Locked ContactPhoto. return GAIR_SUCCESS");
_tcscpy_s(pai->filename, SIZEOF(pai->filename) ,dbv.ptszVal);
- pai->format = GetImageFormat(pai->filename);
+ pai->format = ProtoGetAvatarFormat(pai->filename);
db_free(&dbv);
return GAIR_SUCCESS;
}
@@ -357,20 +326,10 @@ INT_PTR GGPROTO::setmyavatar(WPARAM wParam, LPARAM lParam)
m_tszUserName, MB_OK | MB_ICONINFORMATION);
return -1;
}
-
-
- TCHAR *szAvType = _tcsrchr(szFilename, '.');
- int iAvType = -1;
- szAvType++;
- if (!_tcsicmp(szAvType, _T("jpg")))
- iAvType = PA_FORMAT_JPEG;
- else if (!_tcsicmp(szAvType, _T("gif")))
- iAvType = PA_FORMAT_GIF;
- else if (!_tcsicmp(szAvType, _T("png")))
- iAvType = PA_FORMAT_PNG;
-
- if ( iAvType == -1) {
- netlog("setmyavatar(): Failed to set user avatar. File %S has incompatible extansion.", szAvType);
+
+ int iAvType = ProtoGetAvatarFormat(szFilename);
+ if ( iAvType == PA_FORMAT_UNKNOWN) {
+ netlog("setmyavatar(): Failed to set user avatar. File %s has incompatible extension.", szFilename);
return -1;
}