summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorSzymon Tokarz <wsx22@o2.pl>2012-11-29 00:24:59 +0000
committerSzymon Tokarz <wsx22@o2.pl>2012-11-29 00:24:59 +0000
commitd38f5bfee7197b4094d189d95fe6ee004576dc1d (patch)
tree60d2b2b7e8e8186dc98932529be2e4fa3be2189e /protocols
parent30707c980d1560b358dbf2671a4d2a26a1e8173c (diff)
Gadu-Gadu protocol: account avatar work
- fixes setting custom avatar (when do it first time or change it to another type) - fixed restoring oryginal avatar when setting new has faild (it's complex mechanism and could need some more work, but i'm hope that this and last commits are enough for now) git-svn-id: http://svn.miranda-ng.org/main/trunk@2553 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r--protocols/Gadu-Gadu/src/avatar.cpp17
-rw-r--r--protocols/Gadu-Gadu/src/gg.h1
-rw-r--r--protocols/Gadu-Gadu/src/services.cpp21
3 files changed, 34 insertions, 5 deletions
diff --git a/protocols/Gadu-Gadu/src/avatar.cpp b/protocols/Gadu-Gadu/src/avatar.cpp
index c5c889e369..d49b888064 100644
--- a/protocols/Gadu-Gadu/src/avatar.cpp
+++ b/protocols/Gadu-Gadu/src/avatar.cpp
@@ -378,13 +378,17 @@ void __cdecl GGPROTO::setavatarthread(void *param)
char szUrl[128], uin[32], *authHeader, *data, *avatardata, content[256], image_ext[4], image_type[11];
int file_fd, avatardatalen, datalen, contentlen, contentendlen, res = 0, repeat = 0;
- netlog("setavatarthread(): started. Trying to set user avatar using %s...", szFilename);
+ netlog("setavatarthread(): started. Trying to set user avatar.");
UIN2ID( db_get_dw(NULL, m_szModuleName, GG_KEY_UIN, 0), uin);
file_fd = _topen(szFilename, _O_RDONLY | _O_BINARY, _S_IREAD);
if (file_fd == -1) {
netlog("setavatarthread(): Failed to open avatar file (%s).", strerror(errno));
mir_free(szFilename);
+ int prevType = db_get_b(NULL, m_szModuleName, GG_KEY_AVATARTYPEPREV, -1);
+ if (prevType != -1)
+ db_set_b(NULL, m_szModuleName, GG_KEY_AVATARTYPE, prevType);
+ db_unset(NULL, m_szModuleName, GG_KEY_AVATARTYPEPREV);
getUserAvatar();
#ifdef DEBUGMODE
netlog("setavatarthread(): end. err1");
@@ -492,10 +496,15 @@ void __cdecl GGPROTO::setavatarthread(void *param)
mir_free(avatardata);
mir_free(data);
- if (res)
+ if (res) {
netlog("setavatarthread(): User avatar set successfully.");
- else
+ } else {
+ int prevType = db_get_b(NULL, m_szModuleName, GG_KEY_AVATARTYPEPREV, -1);
+ if (prevType != -1)
+ db_set_b(NULL, m_szModuleName, GG_KEY_AVATARTYPE, prevType);
netlog("setavatarthread(): Failed to set user avatar.");
+ }
+ db_unset(NULL, m_szModuleName, GG_KEY_AVATARTYPEPREV);
mir_free(szFilename);
getUserAvatar();
@@ -507,7 +516,7 @@ void __cdecl GGPROTO::setavatarthread(void *param)
void GGPROTO::setAvatar(const TCHAR *szFilename)
{
#ifdef DEBUGMODE
- netlog("setAvatar(): forkthread 3 GGPROTO::setavatarthread");
+ netlog("setAvatar(): forkthread 3 GGPROTO::setavatarthread");
#endif
forkthread(&GGPROTO::setavatarthread, mir_tstrdup(szFilename));
}
diff --git a/protocols/Gadu-Gadu/src/gg.h b/protocols/Gadu-Gadu/src/gg.h
index cb1d44d3a5..64cb806ff5 100644
--- a/protocols/Gadu-Gadu/src/gg.h
+++ b/protocols/Gadu-Gadu/src/gg.h
@@ -194,6 +194,7 @@ typedef struct
#define GG_KEY_AVATARTS "AvatarTs" // Contact's avatar Timestamp
#define GG_KEY_AVATARTYPE "AvatarType" // Contact's avatar format
+#define GG_KEY_AVATARTYPEPREV "AvatarTypePrev" // Contact's previous avatar format (during setting new avatar)
#define GG_KEYDEF_AVATARTYPE PA_FORMAT_UNKNOWN
#define GG_KEY_AVATARREQUESTED "AvatarRequested" // When contact's avatar is requested
diff --git a/protocols/Gadu-Gadu/src/services.cpp b/protocols/Gadu-Gadu/src/services.cpp
index ce576aa214..5caf23f08c 100644
--- a/protocols/Gadu-Gadu/src/services.cpp
+++ b/protocols/Gadu-Gadu/src/services.cpp
@@ -290,10 +290,29 @@ INT_PTR GGPROTO::setmyavatar(WPARAM wParam, LPARAM lParam)
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);
+ return -1;
+ }
+
+ db_set_b(NULL, m_szModuleName, GG_KEY_AVATARTYPEPREV, db_get_b(NULL, m_szModuleName, GG_KEY_AVATARTYPE, -1));
+ db_set_b(NULL, m_szModuleName, GG_KEY_AVATARTYPE, (BYTE)iAvType);
+
TCHAR szMyFilename[MAX_PATH];
getAvatarFilename(NULL, szMyFilename, SIZEOF(szMyFilename));
if ( _tcscmp(szFilename, szMyFilename) && !CopyFile(szFilename, szMyFilename, FALSE)) {
- netlog("setmyavatar(): Failed to set user avatar. File %s could not be created/overwritten.", szMyFilename);
+ netlog("setmyavatar(): Failed to set user avatar. File with type %d could not be created/overwritten.", iAvType);
return -1;
}