diff options
author | George Hazan <ghazan@miranda.im> | 2018-04-02 18:47:13 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-04-02 18:47:13 +0300 |
commit | da1cc0bffab6ca2b3ffe91c03d798e6f5d3af036 (patch) | |
tree | 5ed562aaa31c58bdf9017b558c6ddb6d0fd909b0 /plugins | |
parent | fe29ca8b0bbcd71cf66f61b572c916e25d6be169 (diff) |
related to #1241 - fix for AVS options' translation
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/AVS/src/main.cpp | 31 | ||||
-rw-r--r-- | plugins/AVS/src/options.cpp | 100 | ||||
-rw-r--r-- | plugins/AVS/src/stdafx.h | 13 | ||||
-rw-r--r-- | plugins/AVS/src/utils.cpp | 1 | ||||
-rw-r--r-- | plugins/AVS/src/version.h | 6 |
5 files changed, 82 insertions, 69 deletions
diff --git a/plugins/AVS/src/main.cpp b/plugins/AVS/src/main.cpp index fd982164a1..2f3577df98 100644 --- a/plugins/AVS/src/main.cpp +++ b/plugins/AVS/src/main.cpp @@ -32,7 +32,7 @@ bool g_shutDown = false; int hLangpack;
-wchar_t g_szDataPath[MAX_PATH]; // user datae path (read at startup only)
+wchar_t g_szDataPath[MAX_PATH]; // user datae path (read at startup only)
BOOL g_AvatarHistoryAvail = FALSE;
HWND hwndSetMyAvatar = nullptr;
@@ -45,10 +45,9 @@ void InitServices(); static int ComparePicture(const protoPicCacheEntry *p1, const protoPicCacheEntry *p2)
{
- if ((mir_strcmp(p1->szProtoname, "Global avatar") == 0) || strstr(p1->szProtoname, "Global avatar"))
- return -1;
- if ((mir_strcmp(p2->szProtoname, "Global avatar") == 0) || strstr(p2->szProtoname, "Global avatar"))
- return 1;
+ if (p1->cacheType != p2->cacheType)
+ return p1->cacheType - p2->cacheType;
+
return mir_strcmp(p1->szProtoname, p2->szProtoname);
}
@@ -122,12 +121,11 @@ static int MetaChanged(WPARAM hMeta, LPARAM hSubContact) static void LoadDefaultInfo()
{
- protoPicCacheEntry *pce = new protoPicCacheEntry;
+ protoPicCacheEntry *pce = new protoPicCacheEntry(PCE_TYPE_GLOBAL);
if (CreateAvatarInCache(0, pce, AVS_DEFAULT) != 1)
db_unset(0, PPICT_MODULE, AVS_DEFAULT);
pce->szProtoname = mir_strdup(AVS_DEFAULT);
- pce->tszAccName = mir_wstrdup(TranslateT("Global avatar"));
g_ProtoPictures.insert(pce);
}
@@ -139,31 +137,28 @@ static void LoadProtoInfo(PROTOCOLDESCRIPTOR *proto) char protoName[MAX_PATH];
mir_snprintf(protoName, "Global avatar for %s accounts", proto->szName);
- wchar_t protoNameTmp[MAX_PATH];
- mir_snwprintf(protoNameTmp, TranslateT("Global avatar for %s accounts"), _A2T(proto->szName));
- protoPicCacheEntry *pce = new protoPicCacheEntry;
+ protoPicCacheEntry *pce = new protoPicCacheEntry(PCE_TYPE_PROTO);
if (CreateAvatarInCache(0, pce, protoName) != 1)
db_unset(0, PPICT_MODULE, protoName);
+ pce->pd = proto;
pce->szProtoname = mir_strdup(protoName);
- pce->tszAccName = mir_wstrdup(protoNameTmp);
g_ProtoPictures.insert(pce);
}
static void LoadAccountInfo(PROTOACCOUNT *acc)
{
- protoPicCacheEntry *pce = new protoPicCacheEntry;
+ protoPicCacheEntry *pce = new protoPicCacheEntry(PCE_TYPE_ACCOUNT);
if (CreateAvatarInCache(0, pce, acc->szModuleName) != 1)
db_unset(0, PPICT_MODULE, acc->szModuleName);
+ pce->pa = acc;
pce->szProtoname = mir_strdup(acc->szModuleName);
- pce->tszAccName = mir_wstrdup(acc->tszAccountName);
g_ProtoPictures.insert(pce);
- pce = new protoPicCacheEntry;
+ pce = new protoPicCacheEntry(PCE_TYPE_ACCOUNT);
CreateAvatarInCache(INVALID_CONTACT_ID, pce, acc->szModuleName);
pce->szProtoname = mir_strdup(acc->szModuleName);
- pce->tszAccName = mir_wstrdup(acc->tszAccountName);
g_MyAvatars.insert(pce);
}
@@ -178,8 +173,8 @@ static int OnAccChanged(WPARAM wParam, LPARAM lParam) case PRAC_REMOVED:
int idx;
- protoPicCacheEntry tmp;
- tmp.szProtoname = mir_strdup(pa->szModuleName);
+ protoPicCacheEntry tmp(PCE_TYPE_ACCOUNT);
+ tmp.szProtoname = pa->szModuleName;
if ((idx = g_ProtoPictures.getIndex(&tmp)) != -1)
g_ProtoPictures.remove(idx);
if ((idx = g_MyAvatars.getIndex(&tmp)) != -1)
@@ -344,7 +339,7 @@ static int ModulesLoaded(WPARAM, LPARAM) LoadAccountInfo(accs[i]);
// Load global avatar
- protoPicCacheEntry *pce = new protoPicCacheEntry;
+ protoPicCacheEntry *pce = new protoPicCacheEntry(PCE_TYPE_GLOBAL);
CreateAvatarInCache(INVALID_CONTACT_ID, pce, "");
pce->szProtoname = mir_strdup("");
g_MyAvatars.insert(pce);
diff --git a/plugins/AVS/src/options.cpp b/plugins/AVS/src/options.cpp index c6de060ac0..da93793d14 100644 --- a/plugins/AVS/src/options.cpp +++ b/plugins/AVS/src/options.cpp @@ -44,14 +44,15 @@ struct WindowData HANDLE hHook; }; -static void RemoveProtoPic(const char *szProto) +static void RemoveProtoPic(protoPicCacheEntry *pce) { - if (szProto == nullptr) + if (pce == nullptr) return; - db_unset(NULL, PPICT_MODULE, szProto); + db_unset(NULL, PPICT_MODULE, pce->szProtoname); - if (!mir_strcmp(AVS_DEFAULT, szProto)) { + // common for all accounts + if (pce->cacheType == PCE_TYPE_GLOBAL) { for (auto &p : g_ProtoPictures) { if (p->szProtoname == nullptr) continue; @@ -63,19 +64,17 @@ static void RemoveProtoPic(const char *szProto) return; } - if (strstr(szProto, "Global avatar for")) { - CMStringA szProtoname; - szProtoname = szProto; - szProtoname.Delete(0, mir_strlen("Global avatar for ")); - szProtoname.Delete(mir_strlen(szProtoname) - mir_strlen(" accounts"), mir_strlen(" accounts")); + // common for all accounts of this proto + if (pce->cacheType == PCE_TYPE_PROTO) { for (auto &p : g_ProtoPictures) { if (p->szProtoname == nullptr) continue; + PROTOACCOUNT *pdescr = Proto_GetAccount(p->szProtoname); - if (pdescr == nullptr && mir_strcmp(p->szProtoname, szProto)) + if (pdescr == nullptr && mir_strcmp(p->szProtoname, pce->szProtoname)) continue; - if (!mir_strcmp(p->szProtoname, szProto) || !mir_strcmp(pdescr->szProtoName, szProtoname)) { + if (!mir_strcmp(p->szProtoname, pce->szProtoname) || !mir_strcmp(pdescr->szProtoName, pce->pd->szName)) { p->clear(); CreateAvatarInCache(0, p, p->szProtoname); NotifyEventHooks(hEventChanged, 0, (LPARAM)p); @@ -85,14 +84,14 @@ static void RemoveProtoPic(const char *szProto) } for (auto &p : g_ProtoPictures) { - if (!mir_strcmp(p->szProtoname, szProto)) { + if (!mir_strcmp(p->szProtoname, pce->szProtoname)) { p->clear(); NotifyEventHooks(hEventChanged, 0, (LPARAM)p); } } } -static void SetProtoPic(char *szProto) +static void SetProtoPic(protoPicCacheEntry *pce) { wchar_t FileName[MAX_PATH], filter[256]; Bitmap_GetFilter(filter, _countof(filter)); @@ -116,49 +115,48 @@ static void SetProtoPic(char *szProto) wchar_t szNewPath[MAX_PATH]; PathToRelativeW(FileName, szNewPath, g_szDataPath); - db_set_ws(NULL, PPICT_MODULE, szProto, szNewPath); + db_set_ws(NULL, PPICT_MODULE, pce->szProtoname, szNewPath); - if (!mir_strcmp(AVS_DEFAULT, szProto)) { + switch(pce->cacheType) { + case PCE_TYPE_GLOBAL: 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); + CreateAvatarInCache(0, p, pce->szProtoname); NotifyEventHooks(hEventChanged, 0, (LPARAM)p); } } - } - else if (strstr(szProto, "Global avatar for")) { - CMStringA szProtoname; - szProtoname = szProto; - szProtoname.Delete(0, mir_strlen("Global avatar for ")); - szProtoname.Delete(mir_strlen(szProtoname) - mir_strlen(" accounts"), mir_strlen(" accounts")); + break; + + case PCE_TYPE_PROTO: for (auto &p : g_ProtoPictures) { PROTOACCOUNT* pdescr = Proto_GetAccount(p->szProtoname); - if (pdescr == nullptr && mir_strcmp(p->szProtoname, szProto)) + if (pdescr == nullptr && mir_strcmp(p->szProtoname, pce->szProtoname)) continue; - if (!mir_strcmp(p->szProtoname, szProto) || !mir_strcmp(pdescr->szProtoName, szProtoname)) { + if (!mir_strcmp(p->szProtoname, pce->szProtoname) || !mir_strcmp(pdescr->szProtoName, pce->pd->szName)) { if (mir_strlen(p->szProtoname) != 0) { if (p->hbmPic == nullptr) { - CreateAvatarInCache(0, p, szProto); + CreateAvatarInCache(0, p, pce->szProtoname); NotifyEventHooks(hEventChanged, 0, (LPARAM)p); } } } } - } - else { + break; + + default: 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 (!mir_strcmp(p->szProtoname, pce->szProtoname) && mir_strlen(p->szProtoname) == mir_strlen(pce->szProtoname)) { if (p->hbmPic != nullptr) DeleteObject(p->hbmPic); memset(p, 0, sizeof(AVATARCACHEENTRY)); - CreateAvatarInCache(0, p, szProto); + CreateAvatarInCache(0, p, pce->szProtoname); NotifyEventHooks(hEventChanged, 0, (LPARAM)p); break; } @@ -166,7 +164,7 @@ static void SetProtoPic(char *szProto) } } -static char* g_selectedProto; +static protoPicCacheEntry *g_selectedProto; static INT_PTR CALLBACK DlgProcOptionsAvatars(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { @@ -265,7 +263,7 @@ static INT_PTR CALLBACK DlgProcOptionsOwn(HWND hwndDlg, UINT msg, WPARAM, LPARAM return FALSE; } -static char* GetProtoFromList(HWND hwndDlg, int iItem) +static protoPicCacheEntry* GetProtoFromList(HWND hwndDlg, int iItem) { LVITEM item; item.mask = LVIF_PARAM; @@ -273,8 +271,7 @@ static char* GetProtoFromList(HWND hwndDlg, int iItem) if (!ListView_GetItem(GetDlgItem(hwndDlg, IDC_PROTOCOLS), &item)) return nullptr; - protoPicCacheEntry *pce = (protoPicCacheEntry *)item.lParam; - return (pce == nullptr) ? nullptr : pce->szProtoname; + return (protoPicCacheEntry*)item.lParam; } static INT_PTR CALLBACK DlgProcOptionsProtos(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) @@ -295,12 +292,25 @@ static INT_PTR CALLBACK DlgProcOptionsProtos(HWND hwndDlg, UINT msg, WPARAM wPar lvc.fmt = LVCFMT_IMAGE | LVCFMT_LEFT; ListView_InsertColumn(hwndList, 0, &lvc); + CMStringW tmp; + LVITEM item = { 0 }; item.mask = LVIF_TEXT | LVIF_PARAM; item.iItem = 1000; for (auto &p : g_ProtoPictures) { + switch (p->cacheType) { + case PCE_TYPE_ACCOUNT: + item.pszText = p->pa->tszAccountName; + break; + case PCE_TYPE_PROTO: + tmp.Format(TranslateT("Global avatar for %s accounts"), _A2T(p->pd->szName).get()); + item.pszText = tmp.GetBuffer(); + break; + default: + item.pszText = TranslateT("Global avatar"); + break; + } item.lParam = (LPARAM)p; - item.pszText = p->tszAccName; int newItem = ListView_InsertItem(hwndList, &item); if (newItem >= 0) ListView_SetCheckState(hwndList, newItem, @@ -319,12 +329,12 @@ static INT_PTR CALLBACK DlgProcOptionsProtos(HWND hwndDlg, UINT msg, WPARAM wPar case IDC_SETPROTOPIC: case IDC_REMOVEPROTOPIC: int iItem = ListView_GetSelectionMark(hwndList); - char *szProto = GetProtoFromList(hwndDlg, iItem); - if (szProto) { + auto *pce = GetProtoFromList(hwndDlg, iItem); + if (pce) { if (LOWORD(wParam) == IDC_SETPROTOPIC) - SetProtoPic(szProto); + SetProtoPic(pce); else - RemoveProtoPic(szProto); + RemoveProtoPic(pce); NMHDR nm = { hwndList, IDC_PROTOCOLS, NM_CLICK }; SendMessage(hwndDlg, WM_NOTIFY, 0, (LPARAM)&nm); @@ -340,7 +350,7 @@ static INT_PTR CALLBACK DlgProcOptionsProtos(HWND hwndDlg, UINT msg, WPARAM wPar avdrq.cbSize = sizeof(avdrq); avdrq.hTargetDC = dis->hDC; avdrq.dwFlags |= AVDRQ_PROTOPICT; - avdrq.szProto = g_selectedProto; + avdrq.szProto = (g_selectedProto) ? g_selectedProto->szProtoname : 0; GetClientRect(GetDlgItem(hwndDlg, IDC_PROTOPIC), &avdrq.rcDraw); CallService(MS_AV_DRAWAVATAR, 0, (LPARAM)&avdrq); } @@ -378,7 +388,7 @@ static INT_PTR CALLBACK DlgProcOptionsProtos(HWND hwndDlg, UINT msg, WPARAM wPar g_selectedProto = GetProtoFromList(hwndDlg, iItem); if (g_selectedProto) { DBVARIANT dbv; - if (!db_get_ws(NULL, PPICT_MODULE, g_selectedProto, &dbv)) { + if (!db_get_ws(NULL, PPICT_MODULE, g_selectedProto->szProtoname, &dbv)) { if (!PathIsAbsoluteW(VARSW(dbv.ptszVal))) { wchar_t szFinalPath[MAX_PATH]; mir_snwprintf(szFinalPath, L"%%miranda_path%%\\%s", dbv.ptszVal); @@ -400,19 +410,19 @@ static INT_PTR CALLBACK DlgProcOptionsProtos(HWND hwndDlg, UINT msg, WPARAM wPar case 0: if (((LPNMHDR)lParam)->code == PSN_APPLY) { for (int i = 0; i < ListView_GetItemCount(hwndList); i++) { - char *szProto = GetProtoFromList(hwndDlg, i); + auto *pce = GetProtoFromList(hwndDlg, i); - BOOL oldVal = db_get_b(NULL, AVS_MODULE, szProto, 1); + BOOL oldVal = db_get_b(NULL, AVS_MODULE, pce->szProtoname, 1); BOOL newVal = ListView_GetCheckState(hwndList, i); if (oldVal && !newVal) - for (auto &hContact : Contacts(szProto)) + for (auto &hContact : Contacts(pce->szProtoname)) DeleteAvatarFromCache(hContact, TRUE); if (newVal) - db_set_b(NULL, AVS_MODULE, szProto, 1); + db_set_b(NULL, AVS_MODULE, pce->szProtoname, 1); else - db_set_b(NULL, AVS_MODULE, szProto, 0); + db_set_b(NULL, AVS_MODULE, pce->szProtoname, 0); } } } diff --git a/plugins/AVS/src/stdafx.h b/plugins/AVS/src/stdafx.h index 14bdbf935e..596b29fecd 100644 --- a/plugins/AVS/src/stdafx.h +++ b/plugins/AVS/src/stdafx.h @@ -27,6 +27,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include <windows.h>
#include <commctrl.h>
#include <time.h>
+#include <malloc.h>
#include <win2k.h>
#include <newpluginapi.h>
@@ -79,15 +80,23 @@ struct CacheNode : public AVATARCACHEENTRY, public MZeroedObject };
// The same fields as AVATARCACHEENTRY + proto name
+#define PCE_TYPE_GLOBAL 0
+#define PCE_TYPE_PROTO 1
+#define PCE_TYPE_ACCOUNT 2
+
struct protoPicCacheEntry : public AVATARCACHEENTRY, public MZeroedObject
{
- protoPicCacheEntry() { memset(this, 0, sizeof(*this)); };
+ protoPicCacheEntry(int _type) : cacheType(_type) {}
~protoPicCacheEntry();
void clear();
char* szProtoname;
- wchar_t* tszAccName;
+ int cacheType = 0;
+ union {
+ PROTOCOLDESCRIPTOR *pd;
+ PROTOACCOUNT *pa;
+ };
};
extern OBJLIST<protoPicCacheEntry> g_ProtoPictures, g_MyAvatars;
diff --git a/plugins/AVS/src/utils.cpp b/plugins/AVS/src/utils.cpp index c3b6dcd83a..0fcfc88c4c 100644 --- a/plugins/AVS/src/utils.cpp +++ b/plugins/AVS/src/utils.cpp @@ -272,7 +272,6 @@ protoPicCacheEntry::~protoPicCacheEntry() if (hbmPic != nullptr)
DeleteObject(hbmPic);
mir_free(szProtoname);
- mir_free(tszAccName);
}
void protoPicCacheEntry::clear()
diff --git a/plugins/AVS/src/version.h b/plugins/AVS/src/version.h index 62074d982d..53b44c9394 100644 --- a/plugins/AVS/src/version.h +++ b/plugins/AVS/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0
-#define __MINOR_VERSION 95
-#define __RELEASE_NUM 3
-#define __BUILD_NUM 4
+#define __MINOR_VERSION 98
+#define __RELEASE_NUM 1
+#define __BUILD_NUM 1
#include <stdver.h>
|