diff options
-rw-r--r-- | plugins/AVS/src/main.cpp | 4 | ||||
-rw-r--r-- | plugins/AVS/src/options.cpp | 92 | ||||
-rw-r--r-- | plugins/AVS/src/services.cpp | 38 | ||||
-rw-r--r-- | plugins/AVS/src/stdafx.h | 2 | ||||
-rw-r--r-- | plugins/AVS/src/utils.cpp | 22 |
5 files changed, 74 insertions, 84 deletions
diff --git a/plugins/AVS/src/main.cpp b/plugins/AVS/src/main.cpp index 774b5c5218..fd982164a1 100644 --- a/plugins/AVS/src/main.cpp +++ b/plugins/AVS/src/main.cpp @@ -52,9 +52,7 @@ static int ComparePicture(const protoPicCacheEntry *p1, const protoPicCacheEntry return mir_strcmp(p1->szProtoname, p2->szProtoname);
}
-OBJLIST<protoPicCacheEntry>
-g_ProtoPictures(10, ComparePicture),
-g_MyAvatars(10, ComparePicture);
+OBJLIST<protoPicCacheEntry> g_ProtoPictures(10, ComparePicture), g_MyAvatars(10, ComparePicture);
char *g_szMetaName = nullptr;
diff --git a/plugins/AVS/src/options.cpp b/plugins/AVS/src/options.cpp index 98a2fd92f8..19024dd883 100644 --- a/plugins/AVS/src/options.cpp +++ b/plugins/AVS/src/options.cpp @@ -29,7 +29,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define DM_AVATARCHANGED (WM_USER + 12) #define DM_PROTOCOLCHANGED (WM_USER + 13) -extern int _DebugPopup(MCONTACT hContact, const char *fmt, ...); extern OBJLIST<protoPicCacheEntry> g_ProtoPictures; extern HANDLE hEventChanged; extern HINSTANCE g_hInst; @@ -53,14 +52,13 @@ static void RemoveProtoPic(const char *szProto) db_unset(NULL, PPICT_MODULE, szProto); if (!mir_strcmp(AVS_DEFAULT, szProto)) { - for (int i = 0; i < g_ProtoPictures.getCount(); i++) { - protoPicCacheEntry &p = g_ProtoPictures[i]; - if (p.szProtoname == nullptr) + for (auto &p : g_ProtoPictures) { + if (p->szProtoname == nullptr) continue; - p.clear(); - CreateAvatarInCache(0, &p, (char *)p.szProtoname); - NotifyEventHooks(hEventChanged, 0, (LPARAM)&p); + p->clear(); + CreateAvatarInCache(0, p, p->szProtoname); + NotifyEventHooks(hEventChanged, 0, (LPARAM)p); } return; } @@ -69,29 +67,26 @@ static void RemoveProtoPic(const char *szProto) char szProtoname[MAX_PATH] = { 0 }; mir_strncpy(szProtoname, szProto, mir_strlen(szProto) - mir_strlen("accounts")); mir_strcpy(szProtoname, strrchr(szProtoname, ' ') + 1); - for (int i = 0; i < g_ProtoPictures.getCount(); i++) { - protoPicCacheEntry &p = g_ProtoPictures[i]; - - if (p.szProtoname == nullptr) + for (auto &p : g_ProtoPictures) { + if (p->szProtoname == nullptr) continue; - PROTOACCOUNT *pdescr = Proto_GetAccount(p.szProtoname); - if (pdescr == nullptr && mir_strcmp(p.szProtoname, szProto)) + PROTOACCOUNT *pdescr = Proto_GetAccount(p->szProtoname); + if (pdescr == nullptr && mir_strcmp(p->szProtoname, szProto)) continue; - if (!mir_strcmp(p.szProtoname, szProto) || !mir_strcmp(pdescr->szProtoName, szProtoname)) { - p.clear(); - CreateAvatarInCache(0, &p, (char *)p.szProtoname); - NotifyEventHooks(hEventChanged, 0, (LPARAM)&p); + if (!mir_strcmp(p->szProtoname, szProto) || !mir_strcmp(pdescr->szProtoName, szProtoname)) { + p->clear(); + CreateAvatarInCache(0, p, p->szProtoname); + NotifyEventHooks(hEventChanged, 0, (LPARAM)p); } } return; } - for (int i = 0; i < g_ProtoPictures.getCount(); i++) { - protoPicCacheEntry &p = g_ProtoPictures[i]; - if (!mir_strcmp(p.szProtoname, szProto)) { - p.clear(); - NotifyEventHooks(hEventChanged, 0, (LPARAM)&p); + for (auto &p : g_ProtoPictures) { + if (!mir_strcmp(p->szProtoname, szProto)) { + p->clear(); + NotifyEventHooks(hEventChanged, 0, (LPARAM)p); } } } @@ -123,14 +118,13 @@ static void SetProtoPic(char *szProto) db_set_ws(NULL, PPICT_MODULE, szProto, szNewPath); if (!mir_strcmp(AVS_DEFAULT, szProto)) { - for (int i = 0; i < g_ProtoPictures.getCount(); i++) { - protoPicCacheEntry& p = g_ProtoPictures[i]; - if (mir_strlen(p.szProtoname) == 0) + for (auto &p : g_ProtoPictures) { + if (mir_strlen(p->szProtoname) == 0) continue; - if (p.hbmPic == nullptr || !mir_strcmp(p.szProtoname, AVS_DEFAULT)) { - CreateAvatarInCache(0, &p, szProto); - NotifyEventHooks(hEventChanged, 0, (LPARAM)&p); + if (p->hbmPic == nullptr || !mir_strcmp(p->szProtoname, AVS_DEFAULT)) { + CreateAvatarInCache(0, p, szProto); + NotifyEventHooks(hEventChanged, 0, (LPARAM)p); } } } @@ -138,34 +132,32 @@ static void SetProtoPic(char *szProto) char szProtoname[MAX_PATH] = { 0 }; mir_strncpy(szProtoname, szProto, mir_strlen(szProto) - mir_strlen("accounts")); mir_strcpy(szProtoname, strrchr(szProtoname, ' ') + 1); - for (int i = 0; i < g_ProtoPictures.getCount(); i++) { - PROTOACCOUNT* pdescr = Proto_GetAccount(g_ProtoPictures[i].szProtoname); - if (pdescr == nullptr && mir_strcmp(g_ProtoPictures[i].szProtoname, szProto)) + for (auto &p : g_ProtoPictures) { + PROTOACCOUNT* pdescr = Proto_GetAccount(p->szProtoname); + if (pdescr == nullptr && mir_strcmp(p->szProtoname, szProto)) continue; - if (!mir_strcmp(g_ProtoPictures[i].szProtoname, szProto) || !mir_strcmp(pdescr->szProtoName, szProtoname)) { - protoPicCacheEntry& p = g_ProtoPictures[i]; - if (mir_strlen(p.szProtoname) != 0) { - if (p.hbmPic == nullptr) { - CreateAvatarInCache(0, &p, szProto); - NotifyEventHooks(hEventChanged, 0, (LPARAM)&p); + if (!mir_strcmp(p->szProtoname, szProto) || !mir_strcmp(pdescr->szProtoName, szProtoname)) { + if (mir_strlen(p->szProtoname) != 0) { + if (p->hbmPic == nullptr) { + CreateAvatarInCache(0, p, szProto); + NotifyEventHooks(hEventChanged, 0, (LPARAM)p); } } } } } else { - for (int i = 0; i < g_ProtoPictures.getCount(); i++) { - protoPicCacheEntry& p = g_ProtoPictures[i]; - if (mir_strlen(p.szProtoname) == 0) + for (auto &p : g_ProtoPictures) { + if (mir_strlen(p->szProtoname) == 0) break; - if (!mir_strcmp(p.szProtoname, szProto) && mir_strlen(p.szProtoname) == mir_strlen(szProto)) { - if (p.hbmPic != nullptr) - DeleteObject(p.hbmPic); - memset(&p, 0, sizeof(AVATARCACHEENTRY)); - CreateAvatarInCache(0, &p, szProto); - NotifyEventHooks(hEventChanged, 0, (LPARAM)&p); + if (!mir_strcmp(p->szProtoname, szProto) && mir_strlen(p->szProtoname) == mir_strlen(szProto)) { + if (p->hbmPic != nullptr) + DeleteObject(p->hbmPic); + memset(p, 0, sizeof(AVATARCACHEENTRY)); + CreateAvatarInCache(0, p, szProto); + NotifyEventHooks(hEventChanged, 0, (LPARAM)p); break; } } @@ -304,13 +296,13 @@ static INT_PTR CALLBACK DlgProcOptionsProtos(HWND hwndDlg, UINT msg, WPARAM wPar LVITEM item = { 0 }; item.mask = LVIF_TEXT | LVIF_PARAM; item.iItem = 1000; - for (int i = 0; i < g_ProtoPictures.getCount(); i++) { - item.lParam = (LPARAM)&g_ProtoPictures[i]; - item.pszText = g_ProtoPictures[i].tszAccName; + for (auto &p : g_ProtoPictures) { + item.lParam = (LPARAM)p; + item.pszText = p->tszAccName; int newItem = ListView_InsertItem(hwndList, &item); if (newItem >= 0) ListView_SetCheckState(hwndList, newItem, - db_get_b(NULL, AVS_MODULE, g_ProtoPictures[i].szProtoname, 1) ? TRUE : FALSE); + db_get_b(NULL, AVS_MODULE, p->szProtoname, 1) ? TRUE : FALSE); } ListView_SetColumnWidth(hwndList, 0, LVSCW_AUTOSIZE); ListView_Arrange(hwndList, LVA_ALIGNLEFT | LVA_ALIGNTOP); diff --git a/plugins/AVS/src/services.cpp b/plugins/AVS/src/services.cpp index a301e3895a..a0b445057a 100644 --- a/plugins/AVS/src/services.cpp +++ b/plugins/AVS/src/services.cpp @@ -728,10 +728,9 @@ INT_PTR DrawAvatarPicture(WPARAM, LPARAM lParam) if (r->szProto == nullptr)
return 0;
- for (int i = 0; i < g_ProtoPictures.getCount(); i++) {
- protoPicCacheEntry& p = g_ProtoPictures[i];
- if (!mir_strcmp(p.szProtoname, r->szProto) && mir_strlen(r->szProto) == mir_strlen(p.szProtoname) && p.hbmPic != nullptr) {
- ace = (AVATARCACHEENTRY *)&g_ProtoPictures[i];
+ for (auto &p : g_ProtoPictures) {
+ if (!mir_strcmp(p->szProtoname, r->szProto) && mir_strlen(r->szProto) == mir_strlen(p->szProtoname) && p->hbmPic != nullptr) {
+ ace = p;
break;
}
}
@@ -771,9 +770,9 @@ INT_PTR GetMyAvatar(WPARAM wParam, LPARAM lParam) if (lParam == 0 || IsBadReadPtr(szProto, 4))
return 0;
- for (int i = 0; i < g_MyAvatars.getCount(); i++)
- if (!mir_strcmp(szProto, g_MyAvatars[i].szProtoname) && g_MyAvatars[i].hbmPic != nullptr)
- return (INT_PTR)&g_MyAvatars[i];
+ for (auto &it : g_MyAvatars)
+ if (!mir_strcmp(szProto, it->szProtoname) && it->hbmPic != nullptr)
+ return (INT_PTR)it;
return 0;
}
@@ -787,8 +786,11 @@ static void ReloadMyAvatar(LPVOID lpParam) char *szProto = (char *)lpParam;
mir_sleep(500);
- for (int i = 0; !g_shutDown && i < g_MyAvatars.getCount(); i++) {
- char *myAvatarProto = g_MyAvatars[i].szProtoname;
+ if (g_shutDown)
+ return;
+
+ for (auto &it : g_MyAvatars) {
+ char *myAvatarProto = it->szProtoname;
if (szProto[0] == 0) {
// Notify to all possibles
@@ -803,11 +805,11 @@ static void ReloadMyAvatar(LPVOID lpParam) else if (mir_strcmp(myAvatarProto, szProto))
continue;
- if (g_MyAvatars[i].hbmPic)
- DeleteObject(g_MyAvatars[i].hbmPic);
+ if (it->hbmPic)
+ DeleteObject(it->hbmPic);
- if (CreateAvatarInCache(INVALID_CONTACT_ID, &g_MyAvatars[i], myAvatarProto) != -1)
- NotifyEventHooks(hMyAvatarChanged, (WPARAM)myAvatarProto, (LPARAM)&g_MyAvatars[i]);
+ if (CreateAvatarInCache(INVALID_CONTACT_ID, it, myAvatarProto) != -1)
+ NotifyEventHooks(hMyAvatarChanged, (WPARAM)myAvatarProto, (LPARAM)it);
else
NotifyEventHooks(hMyAvatarChanged, (WPARAM)myAvatarProto, 0);
}
@@ -821,13 +823,13 @@ INT_PTR ReportMyAvatarChanged(WPARAM wParam, LPARAM) if (proto == nullptr)
return -1;
- for (int i = 0; i < g_MyAvatars.getCount(); i++) {
- if (g_MyAvatars[i].dwFlags & AVS_IGNORENOTIFY)
+ for (auto &it : g_MyAvatars) {
+ if (it->dwFlags & AVS_IGNORENOTIFY)
continue;
- if (!mir_strcmp(g_MyAvatars[i].szProtoname, proto)) {
- LPVOID lpParam = (void *)malloc(mir_strlen(g_MyAvatars[i].szProtoname) + 2);
- mir_strcpy((char *)lpParam, g_MyAvatars[i].szProtoname);
+ if (!mir_strcmp(it->szProtoname, proto)) {
+ LPVOID lpParam = (void *)malloc(mir_strlen(it->szProtoname) + 2);
+ mir_strcpy((char *)lpParam, it->szProtoname);
mir_forkthread(ReloadMyAvatar, lpParam);
return 0;
}
diff --git a/plugins/AVS/src/stdafx.h b/plugins/AVS/src/stdafx.h index d055b0f886..973e916551 100644 --- a/plugins/AVS/src/stdafx.h +++ b/plugins/AVS/src/stdafx.h @@ -127,7 +127,7 @@ void MyPathToAbsolute(const wchar_t *ptszPath, wchar_t *ptszDest); HBITMAP LoadPNG(struct AVATARCACHEENTRY *ace, char *szFilename);
void UnloadCache(void);
-int CreateAvatarInCache(MCONTACT hContact, AVATARCACHEENTRY *ace, char *szProto);
+int CreateAvatarInCache(MCONTACT hContact, AVATARCACHEENTRY *ace, const char *szProto);
void DeleteAvatarFromCache(MCONTACT hContact, bool bForever);
void PicLoader(LPVOID param);
void NotifyMetaAware(MCONTACT hContact, CacheNode *node = NULL, AVATARCACHEENTRY *ace = (AVATARCACHEENTRY*)-1);
diff --git a/plugins/AVS/src/utils.cpp b/plugins/AVS/src/utils.cpp index bb794dd84d..c3b6dcd83a 100644 --- a/plugins/AVS/src/utils.cpp +++ b/plugins/AVS/src/utils.cpp @@ -65,7 +65,7 @@ void MakePathRelative(MCONTACT hContact) // create the avatar in cache
// returns 0 if not created (no avatar), iIndex otherwise, -2 if has to request avatar, -3 if avatar too big
-int CreateAvatarInCache(MCONTACT hContact, AVATARCACHEENTRY *ace, char *szProto)
+int CreateAvatarInCache(MCONTACT hContact, AVATARCACHEENTRY *ace, const char *szProto)
{
ptrW tszValue;
wchar_t tszFilename[MAX_PATH]; tszFilename[0] = 0;
@@ -381,13 +381,11 @@ BOOL Proto_IsFetchingWhenContactOfflineAllowed(const char *proto) protoPicCacheEntry* GetProtoDefaultAvatar(MCONTACT hContact)
{
char *szProto = GetContactProto(hContact);
- if (szProto) {
- for (int i = 0; i < g_ProtoPictures.getCount(); i++) {
- protoPicCacheEntry& p = g_ProtoPictures[i];
- if (!mir_strcmp(p.szProtoname, szProto) && p.hbmPic != nullptr)
- return &g_ProtoPictures[i];
- }
- }
+ if (szProto)
+ for (auto &p : g_ProtoPictures)
+ if (!mir_strcmp(p->szProtoname, szProto) && p->hbmPic != nullptr)
+ return p;
+
return nullptr;
}
@@ -445,12 +443,12 @@ void DeleteGlobalUserAvatar() void SetIgnoreNotify(char *protocol, BOOL ignore)
{
- for (int i = 0; i < g_MyAvatars.getCount(); i++) {
- if (protocol == nullptr || !mir_strcmp(g_MyAvatars[i].szProtoname, protocol)) {
+ for (auto &it : g_MyAvatars) {
+ if (protocol == nullptr || !mir_strcmp(it->szProtoname, protocol)) {
if (ignore)
- g_MyAvatars[i].dwFlags |= AVS_IGNORENOTIFY;
+ it->dwFlags |= AVS_IGNORENOTIFY;
else
- g_MyAvatars[i].dwFlags &= ~AVS_IGNORENOTIFY;
+ it->dwFlags &= ~AVS_IGNORENOTIFY;
}
}
}
|