From adf7fec7b1e32e93998e08cd41e9d84852db1758 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 6 Apr 2016 13:39:41 +0000 Subject: clist_modern: - fix for a nightmare with contsct renaming; - end of a crutch with caching 'Unknown contact'; - cache control over the contact's name went to the core; - code cleaning; - version bump; git-svn-id: http://svn.miranda-ng.org/main/trunk@16596 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Clist_modern/src/modern_clcitems.cpp | 12 ++- plugins/Clist_modern/src/modern_clcpaint.h | 2 +- plugins/Clist_modern/src/modern_clist.h | 3 - plugins/Clist_modern/src/modern_clistsettings.cpp | 86 ++-------------- plugins/Clist_modern/src/modern_commonprototypes.h | 32 +++--- plugins/Clist_modern/src/modern_skinengine.h | 20 ++-- plugins/Clist_modern/src/modern_skinselector.h | 8 +- plugins/Clist_modern/src/version.h | 2 +- src/mir_app/src/clistsettings.cpp | 111 ++++++++++++--------- 9 files changed, 112 insertions(+), 164 deletions(-) diff --git a/plugins/Clist_modern/src/modern_clcitems.cpp b/plugins/Clist_modern/src/modern_clcitems.cpp index 087d67ab56..d9d6b31f46 100644 --- a/plugins/Clist_modern/src/modern_clcitems.cpp +++ b/plugins/Clist_modern/src/modern_clcitems.cpp @@ -137,7 +137,7 @@ void cli_FreeContact(ClcContact *p) corecli.pfnFreeContact(p); } -void cli_FreeGroup(ClcGroup* group) +void cli_FreeGroup(ClcGroup *group) { corecli.pfnFreeGroup(group); ClearRowByIndexCache(); @@ -622,13 +622,13 @@ ClcCacheEntry* cliCreateCacheItem(MCONTACT hContact) void cliInvalidateDisplayNameCacheEntry(MCONTACT hContact) { - if (hContact == INVALID_CONTACT_ID) - corecli.pfnInvalidateDisplayNameCacheEntry(INVALID_CONTACT_ID); - else { + if (hContact != INVALID_CONTACT_ID) { ClcCacheEntry *p = pcli->pfnGetCacheEntry(hContact); if (p) p->m_iStatus = 0; } + + corecli.pfnInvalidateDisplayNameCacheEntry(hContact); } void cli_SetContactCheckboxes(ClcContact *cc, int checked) @@ -687,12 +687,14 @@ int __fastcall CLVM_GetContactHiddenStatus(MCONTACT hContact, char *szProto, Clc TCHAR szGroupMask[256]; DWORD dwLocalMask; ClcCacheEntry *pdnce = pcli->pfnGetCacheEntry(hContact); - // always hide subcontacts (but show them on embedded contact lists) + // always hide subcontacts (but show them on embedded contact lists) if (dat != NULL && dat->IsMetaContactsEnabled && db_mc_isSub(hContact)) return -1; //subcontact + if (pdnce && pdnce->m_bIsUnknown && dat != NULL && !dat->force_in_dialog) return 1; //'Unknown Contact' + if (dat != NULL && dat->filterSearch && pdnce && pdnce->tszName) { // search filtering TCHAR *lowered_name = CharLowerW(NEWTSTR_ALLOCA(pdnce->tszName)); diff --git a/plugins/Clist_modern/src/modern_clcpaint.h b/plugins/Clist_modern/src/modern_clcpaint.h index 879452125f..377f27d6eb 100644 --- a/plugins/Clist_modern/src/modern_clcpaint.h +++ b/plugins/Clist_modern/src/modern_clcpaint.h @@ -92,7 +92,7 @@ private: //ADD new item above here hi_LastItem } enumHASHINDEX; - static const char * HASHTEXT[hi_LastItem]; + static const char* HASHTEXT[hi_LastItem]; static DWORD HASH[hi_LastItem]; void _FillQuickHash(); diff --git a/plugins/Clist_modern/src/modern_clist.h b/plugins/Clist_modern/src/modern_clist.h index 9747554acc..5fc23f6720 100644 --- a/plugins/Clist_modern/src/modern_clist.h +++ b/plugins/Clist_modern/src/modern_clist.h @@ -96,9 +96,6 @@ struct ClcCacheEntry : public ClcCacheEntryBase HANDLE hTimeZone; DWORD dwLastMsgTime; - void getName(void); - void freeName(void); - int __forceinline getStatus() const { return (this == NULL) ? ID_STATUS_OFFLINE : m_iStatus; } diff --git a/plugins/Clist_modern/src/modern_clistsettings.cpp b/plugins/Clist_modern/src/modern_clistsettings.cpp index 188e0a6e7f..a9a4a59ac2 100644 --- a/plugins/Clist_modern/src/modern_clistsettings.cpp +++ b/plugins/Clist_modern/src/modern_clistsettings.cpp @@ -35,7 +35,7 @@ static int displayNameCacheSize; LIST clistCache(50, NumericKeySortT); -int GetStatusForContact(MCONTACT hContact, char *szProto); +int GetStatusForContact(MCONTACT hContact, char *szProto); TCHAR* UnknownConctactTranslatedName = NULL; void InitDisplayNameCache(void) @@ -81,7 +81,7 @@ void CListSettings_FreeCacheItemDataOption(ClcCacheEntry *pDst, DWORD flag) return; if (flag & CCI_NAME) - pDst->freeName(); + mir_free_and_nil(pDst->tszName); if (flag & CCI_GROUP) mir_free_and_nil(pDst->tszGroup); @@ -102,14 +102,7 @@ void CListSettings_CopyCacheItems(ClcCacheEntry *pDst, ClcCacheEntry *pSrc, DWOR if (!pDst || !pSrc) return; CListSettings_FreeCacheItemDataOption(pDst, flag); - if (flag & CCI_NAME) { - pDst->m_bIsUnknown = pSrc->m_bIsUnknown; - if (pSrc->m_bIsUnknown) - pDst->tszName = pSrc->tszName; - else - pDst->tszName = mir_tstrdup(pSrc->tszName); - } - + if (flag & CCI_NAME) pDst->tszName = mir_tstrdup(pSrc->tszName); if (flag & CCI_GROUP) pDst->tszGroup = mir_tstrdup(pSrc->tszGroup); if (flag & CCI_PROTO) pDst->m_pszProto = pSrc->m_pszProto; if (flag & CCI_STATUS) pDst->m_iStatus = pSrc->m_iStatus; @@ -169,7 +162,7 @@ int CListSettings_SetToCache(ClcCacheEntry *pSrc, DWORD flag) void cliFreeCacheItem(ClcCacheEntry *p) { - p->freeName(); + mir_free_and_nil(p->tszName); mir_free_and_nil(p->tszGroup); mir_free_and_nil(p->szSecondLineText); mir_free_and_nil(p->szThirdLineText); @@ -184,18 +177,20 @@ void cliCheckCacheItem(ClcCacheEntry *pdnce) if (pdnce->hContact == NULL) { //selfcontact if (!pdnce->tszName) - pdnce->getName(); + pdnce->tszName = pcli->pfnGetContactDisplayName(NULL, GCDNF_NOCACHE); return; } if (pdnce->m_pszProto == NULL) { pdnce->m_pszProto = GetContactProto(pdnce->hContact); if (pdnce->m_pszProto && pdnce->tszName) - pdnce->freeName(); + mir_free_and_nil(pdnce->tszName); } - if (pdnce->tszName == NULL) - pdnce->getName(); + if (pdnce->tszName == NULL) { + pdnce->tszName = pcli->pfnGetContactDisplayName(pdnce->hContact, GCDNF_NOCACHE); + pdnce->m_bIsUnknown = mir_tstrcmp(pdnce->tszName, UnknownConctactTranslatedName); + } if (pdnce->m_iStatus == 0) //very strange look status sort is broken let always reread status pdnce->m_iStatus = GetStatusForContact(pdnce->hContact, pdnce->m_pszProto); @@ -263,35 +258,6 @@ int GetStatusForContact(MCONTACT hContact, char *szProto) return (szProto) ? db_get_w(hContact, szProto, "Status", ID_STATUS_OFFLINE) : ID_STATUS_OFFLINE; } -void ClcCacheEntry::freeName() -{ - if (!m_bIsUnknown) - mir_free(tszName); - else - m_bIsUnknown = false; - tszName = NULL; -} - -void ClcCacheEntry::getName() -{ - freeName(); - - if (m_pszProto == NULL) { - LBL_Unknown: - tszName = UnknownConctactTranslatedName; - m_bIsUnknown = true; - return; - } - - tszName = pcli->pfnGetContactDisplayName(hContact, GCDNF_NOCACHE); - if (!mir_tstrcmp(tszName, UnknownConctactTranslatedName)) { - mir_free(tszName); - goto LBL_Unknown; - } - - m_bIsUnknown = false; -} - int GetContactInfosForSort(MCONTACT hContact, char **Proto, TCHAR **Name, int *Status) { ClcCacheEntry *cacheEntry = NULL; @@ -326,30 +292,6 @@ int MetaStatusChanged(WPARAM hMeta, LPARAM) return 0; } -static void Dbwcs2tstr(DBCONTACTWRITESETTING *cws, TCHAR* &pStr) -{ - mir_free(pStr); - - switch (cws->value.type) { - case -1: - case DBVT_DELETED: - pStr = NULL; - break; - - case DBVT_UTF8: - pStr = mir_utf8decodeT(cws->value.pszVal); - break; - - case DBVT_ASCIIZ: - pStr = mir_a2t(cws->value.pszVal); - break; - - case DBVT_WCHAR: - pStr = mir_u2t(cws->value.ptszVal); - break; - } -} - int ContactSettingChanged(WPARAM hContact, LPARAM lParam) { if (MirandaExiting() || !pcli || hContact == NULL) @@ -402,16 +344,10 @@ int ContactSettingChanged(WPARAM hContact, LPARAM lParam) } if (!strcmp(cws->szModule, "CList")) { - //name is null or (setting is myhandle) + // name is null or (setting is myhandle) if (!strcmp(cws->szSetting, "Rate")) pcli->pfnClcBroadcast(CLM_AUTOREBUILD, 0, 0); - else if (!strcmp(cws->szSetting, "MyHandle")) - pdnce->getName(); - - else if (!strcmp(cws->szSetting, "Group")) - Dbwcs2tstr(cws, pdnce->tszGroup); - else if (!strcmp(cws->szSetting, "NotOnList")) pdnce->NotOnList = cws->value.bVal; diff --git a/plugins/Clist_modern/src/modern_commonprototypes.h b/plugins/Clist_modern/src/modern_commonprototypes.h index af25e9d41e..98e125145c 100644 --- a/plugins/Clist_modern/src/modern_commonprototypes.h +++ b/plugins/Clist_modern/src/modern_commonprototypes.h @@ -27,8 +27,8 @@ extern FRAMEWND *g_pfwFrames; extern int g_nFramesCount; extern RECT g_rcEdgeSizingRect; extern FRAMEWND *wndFrameEventArea; -extern ROWCELL * gl_RowTabAccess[]; -extern ROWCELL * gl_RowRoot; +extern ROWCELL *gl_RowTabAccess[]; +extern ROWCELL *gl_RowRoot; extern HIMAGELIST hAvatarOverlays; extern int g_nTitleBarHeight; extern BOOL g_bTransparentFlag; @@ -40,12 +40,12 @@ extern BYTE nameOrder[]; extern SortedList lContactsCache; extern BOOL g_flag_bOnModulesLoadedCalled; extern SKINOBJECTSLIST g_SkinObjectList; -extern CURRWNDIMAGEDATA * g_pCachedWindow; +extern CURRWNDIMAGEDATA *g_pCachedWindow; extern BOOL g_mutex_bLockUpdating; extern STATUSBARDATA g_StatusBarData; extern SKINOBJECTSLIST g_SkinObjectList; -extern CURRWNDIMAGEDATA * g_pCachedWindow; -extern char * g_szConnectingProto; +extern CURRWNDIMAGEDATA *g_pCachedWindow; +extern char *g_szConnectingProto; extern BOOL g_mutex_bLockUpdating; extern int g_mutex_nCalcRowHeightLock; extern int g_mutex_bOnTrayRightClick; @@ -75,13 +75,13 @@ typedef INT_PTR(*PSYNCCALLBACKPROC)(WPARAM, LPARAM); /* CLCItems */ -bool CLCItems_IsShowOfflineGroup(ClcGroup* group); +bool CLCItems_IsShowOfflineGroup(ClcGroup *group); /* CListMod */ int CListMod_HideWindow(); /* CLUI */ -HANDLE RegisterIcolibIconHandle(char * szIcoID, char *szSectionName, char * szDescription, TCHAR * tszDefaultFile, int iDefaultIndex, HINSTANCE hDefaultModule, int iDefaultResource); +HANDLE RegisterIcolibIconHandle(char *szIcoID, char *szSectionName, char *szDescription, TCHAR *tszDefaultFile, int iDefaultIndex, HINSTANCE hDefaultModule, int iDefaultResource); void CLUI_UpdateAeroGlass(); void CLUI_ChangeWindowMode(); BOOL CLUI_CheckOwnedByClui(HWND hwnd); @@ -104,14 +104,14 @@ UINT_PTR CLUI_SafeSetTimer(HWND hwnd, int ID, int Timeout, TIMERPROC proc); int CLUIUnreadEmailCountChanged(WPARAM wParam, LPARAM lParam); /* GDIPlus */ -BOOL GDIPlus_AlphaBlend(HDC hdcDest, int nXOriginDest, int nYOriginDest, int nWidthDest, int nHeightDest, HDC hdcSrc, int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc, BLENDFUNCTION * blendFunction); +BOOL GDIPlus_AlphaBlend(HDC hdcDest, int nXOriginDest, int nYOriginDest, int nWidthDest, int nHeightDest, HDC hdcSrc, int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc, BLENDFUNCTION *blendFunction); HBITMAP GDIPlus_LoadGlyphImage(const TCHAR *szFileName); /* EventArea */ void EventArea_ConfigureEventArea(); /* ModernSkinButton */ -int ModernSkinButton_AddButton(HWND parent, char * ID, char * CommandService, char * StateDefService, char * HandeService, int Left, int Top, int Right, int Bottom, DWORD AlignedTo, TCHAR * Hint, char * DBkey, char * TypeDef, int MinWidth, int MinHeight); +int ModernSkinButton_AddButton(HWND parent, char *ID, char *CommandService, char *StateDefService, char *HandeService, int Left, int Top, int Right, int Bottom, DWORD AlignedTo, TCHAR *Hint, char *DBkey, char *TypeDef, int MinWidth, int MinHeight); int ModernSkinButtonLoadModule(); int ModernSkinButton_ReposButtons(HWND parent, BYTE draw, RECT *r); int ModernSkinButtonUnloadModule(WPARAM, LPARAM); @@ -131,10 +131,10 @@ int ske_DrawImageAt(HDC hdc, RECT *rc); BOOL ske_DrawIconEx(HDC hdc, int xLeft, int yTop, HICON hIcon, int cxWidth, int cyWidth, UINT istepIfAniCur, HBRUSH hbrFlickerFreeDraw, UINT diFlags); int ske_DrawNonFramedObjects(BOOL Erase, RECT *r); BOOL ske_DrawText(HDC hdc, LPCTSTR lpString, int nCount, RECT *lpRect, UINT format); -LPSKINOBJECTDESCRIPTOR ske_FindObjectByName(const char * szName, BYTE objType, SKINOBJECTSLIST* Skin); +LPSKINOBJECTDESCRIPTOR ske_FindObjectByName(const char *szName, BYTE objType, SKINOBJECTSLIST *Skin); HBITMAP ske_GetCurrentWindowImage(); int ske_GetFullFilename(TCHAR *buf, const TCHAR *file, TCHAR *skinfolder, BOOL madeAbsolute); -int ske_GetSkinFolder(TCHAR *szFileName, char * t2); +int ske_GetSkinFolder(TCHAR *szFileName, char *t2); BOOL ske_ImageList_DrawEx(HIMAGELIST himl, int i, HDC hdcDst, int x, int y, int dx, int dy, COLORREF rgbBk, COLORREF rgbFg, UINT fStyle); HICON ske_ImageList_GetIcon(HIMAGELIST himl, int i); int ske_JustUpdateWindowImageRect(RECT *rty); @@ -188,7 +188,7 @@ char* GetContactCachedProtocol(MCONTACT hContact); char* GetParamN(char *string, char *buf, int buflen, BYTE paramN, char Delim, BOOL SkipSpaces); //mod_skin_selector.c WCHAR* GetParamN(WCHAR *string, WCHAR *buf, int buflen, BYTE paramN, WCHAR Delim, BOOL SkipSpaces); DWORD CompareContacts2_getLMTime(MCONTACT u); //contact.c -DWORD mod_CalcHash(const char * a); //mod_skin_selector.c +DWORD mod_CalcHash(const char *a); //mod_skin_selector.c HICON cliGetIconFromStatusMode(MCONTACT hContact, const char *szProto, int status); //clistmod.c HICON GetMainStatusOverlay(int STATUS); //clc.c int __fastcall CLVM_GetContactHiddenStatus(MCONTACT hContact, char *szStatus, ClcData *dat); //clcitems.c @@ -209,7 +209,7 @@ int OnFrameTitleBarBackgroundChange(WPARAM wParam, LPARAM lParam); int QueueAllFramesUpdating(bool); //cluiframes.c int RecursiveDeleteMenu(HMENU hMenu); //clistmenus.c int ModernSkinButtonRedrawAll(); //modern_button.c -int RegisterButtonByParce(char * ObjectName, char * Params); //mod_skin_selector.c +int RegisterButtonByParce(char *ObjectName, char *Params); //mod_skin_selector.c int RestoreAllContactData(ClcData *dat); //cache_funcs.c int SkinSelector_DeleteMask(MODERNMASK *mm); //mod_skin_selector.c @@ -272,17 +272,17 @@ LRESULT cli_ProcessExternalMessages(HWND hwnd, ClcData *dat, UINT msg, WPARAM wP CListEvent* cli_AddEvent(CLISTEVENT *cle); LRESULT CALLBACK cli_ContactListControlWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); int cliShowHide(WPARAM wParam, LPARAM lParam); -BOOL CLUI__cliInvalidateRect(HWND hWnd, CONST RECT* lpRect, BOOL bErase); +BOOL CLUI__cliInvalidateRect(HWND hWnd, CONST RECT *lpRect, BOOL bErase); int cliCompareContacts(const ClcContact *contact1, const ClcContact *contact2); int cliFindItem(HWND hwnd, ClcData *dat, DWORD dwItem, ClcContact **contact, ClcGroup **subgroup, int *isVisible); int cliTrayIconPauseAutoHide(WPARAM wParam, LPARAM lParam); -void cliCluiProtocolStatusChanged(int status, const char * proto); +void cliCluiProtocolStatusChanged(int status, const char *proto); void cliInvalidateDisplayNameCacheEntry(MCONTACT hContact); void cliCheckCacheItem(ClcCacheEntry *pdnce); void cli_SaveStateAndRebuildList(HWND hwnd, ClcData *dat); void CLUI_cli_LoadCluiGlobalOpts(void); INT_PTR cli_TrayIconProcessMessage(WPARAM wParam, LPARAM lParam); -BOOL CLUI__cliInvalidateRect(HWND hWnd, CONST RECT* lpRect, BOOL bErase); +BOOL CLUI__cliInvalidateRect(HWND hWnd, CONST RECT *lpRect, BOOL bErase); int cliTrayIconInit(HWND hwnd); int cliTrayCalcChanged(const char *szChangedProto, int averageMode, int netProtoCount); diff --git a/plugins/Clist_modern/src/modern_skinengine.h b/plugins/Clist_modern/src/modern_skinengine.h index 70b7a9b838..710b8d2789 100644 --- a/plugins/Clist_modern/src/modern_skinengine.h +++ b/plugins/Clist_modern/src/modern_skinengine.h @@ -70,17 +70,17 @@ public: enum { IT_UNKNOWN, IT_FILE, IT_RESOURCE }; - typedef HRESULT(*ParserCallback_t)(const char * szSection, const char * szKey, const char * szValue, IniParser * This); + typedef HRESULT(*ParserCallback_t)(const char *szSection, const char *szKey, const char *szValue, IniParser *This); - IniParser(TCHAR * szFileName, BYTE flags = FLAG_WITH_SETTINGS); + IniParser(TCHAR *szFileName, BYTE flags = FLAG_WITH_SETTINGS); IniParser(HINSTANCE hInst, const char *resourceName, const char *resourceType, BYTE flags = FLAG_ONLY_OBJECTS); ~IniParser(); bool CheckOK() { return _isValid; } HRESULT Parse(ParserCallback_t pLineCallBackProc, LPARAM lParam); - static HRESULT WriteStrToDb(const char * szSection, const char * szKey, const char * szValue, IniParser * This); - static int GetSkinFolder(IN const TCHAR * szFileName, OUT TCHAR * pszFolderName); + static HRESULT WriteStrToDb(const char *szSection, const char *szKey, const char *szValue, IniParser *This); + static int GetSkinFolder(IN const TCHAR *szFileName, OUT TCHAR *pszFolderName); private: // common @@ -93,24 +93,22 @@ private: int _nLine; void _DoInit(); - BOOL _DoParseLine(char * szLine); + BOOL _DoParseLine(char *szLine); // Processing File HRESULT _DoParseFile(); - FILE * _hFile; + FILE* _hFile; // Processing resource - void _LoadResourceIni(HINSTANCE hInst, const char * resourceName, const char * resourceType); + void _LoadResourceIni(HINSTANCE hInst, const char *resourceName, const char *resourceType); HRESULT _DoParseResource(); - const char * _RemoveTailings(const char * szLine, size_t& len); + const char* _RemoveTailings(const char *szLine, size_t &len); HGLOBAL _hGlobalRes; DWORD _dwSizeOfRes; - char * _pPosition; + char* _pPosition; BYTE _Flags; - - }; diff --git a/plugins/Clist_modern/src/modern_skinselector.h b/plugins/Clist_modern/src/modern_skinselector.h index e0cc3606c7..984d4b895a 100644 --- a/plugins/Clist_modern/src/modern_skinselector.h +++ b/plugins/Clist_modern/src/modern_skinselector.h @@ -69,11 +69,11 @@ int AddStrModernMaskToList(DWORD maskID, char *szStr, char *objectName, LISTMODE int SortMaskList(LISTMODERNMASK *mmList); int ClearMaskList(LISTMODERNMASK *mmTemplateList); -BOOL CompareStrWithModernMask(char * szValue, MODERNMASK *mmTemplate); -DWORD mod_CalcHash(const char * a); -int RegisterObjectByParce(char * ObjectName, char *Params); +BOOL CompareStrWithModernMask(char *szValue, MODERNMASK *mmTemplate); +DWORD mod_CalcHash(const char *a); +int RegisterObjectByParce(char *ObjectName, char *Params); SKINOBJECTDESCRIPTOR* skin_FindObjectByRequest(char *szValue, LISTMODERNMASK *mmTemplateList); SKINOBJECTDESCRIPTOR* skin_FindObjectByMask(MODERNMASK *mm, LISTMODERNMASK *mmTemplateList); -TCHAR * GetParamNT(char * string, TCHAR * buf, int buflen, BYTE paramN, char Delim, BOOL SkipSpaces); +TCHAR * GetParamNT(char *string, TCHAR *buf, int buflen, BYTE paramN, char Delim, BOOL SkipSpaces); int SkinDrawGlyphMask(HDC hdc, RECT *rcSize, RECT *rcClip, MODERNMASK *ModernMask); #endif diff --git a/plugins/Clist_modern/src/version.h b/plugins/Clist_modern/src/version.h index 29e3cbde4f..bbda4934c2 100644 --- a/plugins/Clist_modern/src/version.h +++ b/plugins/Clist_modern/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 9 #define __RELEASE_NUM 1 -#define __BUILD_NUM 3 +#define __BUILD_NUM 4 #include diff --git a/src/mir_app/src/clistsettings.cpp b/src/mir_app/src/clistsettings.cpp index c499da4265..7d35be8aeb 100644 --- a/src/mir_app/src/clistsettings.cpp +++ b/src/mir_app/src/clistsettings.cpp @@ -29,7 +29,7 @@ static LIST clistCache(50, NumericKeySortT); void FreeDisplayNameCache(void) { - for (int i=0; i < clistCache.getCount(); i++) { + for (int i = 0; i < clistCache.getCount(); i++) { cli.pfnFreeCacheItem(clistCache[i]); mir_free(clistCache[i]); } @@ -41,7 +41,7 @@ void FreeDisplayNameCache(void) ClcCacheEntry* fnCreateCacheItem(MCONTACT hContact) { - ClcCacheEntry* p = (ClcCacheEntry*)mir_calloc(sizeof(ClcCacheEntry)); + ClcCacheEntry *p = (ClcCacheEntry*)mir_calloc(sizeof(ClcCacheEntry)); if (p == NULL) return NULL; @@ -51,13 +51,10 @@ ClcCacheEntry* fnCreateCacheItem(MCONTACT hContact) void fnCheckCacheItem(ClcCacheEntry *p) { - DBVARIANT dbv; if (p->tszGroup == NULL) { - if (!db_get_ts(p->hContact, "CList", "Group", &dbv)) { - p->tszGroup = mir_tstrdup(dbv.ptszVal); - mir_free(dbv.ptszVal); - } - else p->tszGroup = mir_tstrdup(_T("")); + p->tszGroup = db_get_tsa(p->hContact, "CList", "Group"); + if (p->tszGroup == NULL) + p->tszGroup = mir_tstrdup(_T("")); } if (p->bIsHidden == -1) @@ -119,7 +116,7 @@ TCHAR* fnGetContactDisplayName(MCONTACT hContact, int mode) if (ci.hContact == NULL) ci.szProto = "ICQ"; ci.dwFlag = ((mode == GCDNF_NOMYHANDLE) ? CNF_DISPLAYNC : CNF_DISPLAY) | CNF_TCHAR; - if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) & ci)) { + if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci)) { if (ci.type == CNFT_ASCIIZ) { if (cacheEntry != NULL) cacheEntry->tszName = ci.pszVal; @@ -127,7 +124,7 @@ TCHAR* fnGetContactDisplayName(MCONTACT hContact, int mode) } if (ci.type == CNFT_DWORD) { - TCHAR *buffer = (TCHAR*) mir_alloc(15 * sizeof(TCHAR)); + TCHAR *buffer = (TCHAR*)mir_alloc(15 * sizeof(TCHAR)); _ltot(ci.dVal, buffer, 10); if (cacheEntry != NULL) cacheEntry->tszName = buffer; @@ -158,44 +155,62 @@ int ContactDeleted(WPARAM wParam, LPARAM) return 0; } -int ContactSettingChanged(WPARAM hContact, LPARAM lParam) +///////////////////////////////////////////////////////////////////////////////////////// + +static void Dbwcs2tstr(DBCONTACTWRITESETTING *cws, TCHAR* &pStr) { - DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING *) lParam; + mir_free(pStr); + + switch (cws->value.type) { + case -1: + case DBVT_DELETED: + pStr = NULL; + break; + + case DBVT_UTF8: + pStr = mir_utf8decodeT(cws->value.pszVal); + break; + + case DBVT_ASCIIZ: + pStr = mir_a2t(cws->value.pszVal); + break; + case DBVT_WCHAR: + pStr = mir_u2t(cws->value.ptszVal); + break; + } +} + +int ContactSettingChanged(WPARAM hContact, LPARAM lParam) +{ // Early exit if (hContact == NULL) return 0; - DBVARIANT dbv; - dbv.pszVal = NULL; - if (!db_get(hContact, "Protocol", "p", &dbv)) { - if (!mir_strcmp(cws->szModule, dbv.pszVal)) { - cli.pfnInvalidateDisplayNameCacheEntry(hContact); - if (!strcmp(cws->szSetting, "UIN") || !strcmp(cws->szSetting, "Nick") || !strcmp(cws->szSetting, "FirstName") - || !strcmp(cws->szSetting, "LastName") || !strcmp(cws->szSetting, "e-mail")) - { - CallService(MS_CLUI_CONTACTRENAMED, hContact, 0); - } - else if (!strcmp(cws->szSetting, "Status")) { - if (!db_get_b(hContact, "CList", "Hidden", 0)) { - if (db_get_b(NULL, "CList", "HideOffline", SETTING_HIDEOFFLINE_DEFAULT)) { - // User's state is changing, and we are hideOffline-ing - if (cws->value.wVal == ID_STATUS_OFFLINE) { - cli.pfnChangeContactIcon(hContact, cli.pfnIconFromStatusMode(cws->szModule, cws->value.wVal, hContact), 0); - CallService(MS_CLUI_CONTACTDELETED, hContact, 0); - mir_free(dbv.pszVal); - return 0; - } - cli.pfnChangeContactIcon(hContact, cli.pfnIconFromStatusMode(cws->szModule, cws->value.wVal, hContact), 1); + DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING*)lParam; + char *szProto = GetContactProto(hContact); + if (!mir_strcmp(cws->szModule, szProto)) { + if (!strcmp(cws->szSetting, "UIN") || !strcmp(cws->szSetting, "Nick") || !strcmp(cws->szSetting, "FirstName") || !strcmp(cws->szSetting, "LastName") || !strcmp(cws->szSetting, "e-mail")) { + ClcCacheEntry *pdnce = cli.pfnGetCacheEntry(hContact); + replaceStrT(pdnce->tszName, NULL); + cli.pfnCheckCacheItem(pdnce); + } + else if (!strcmp(cws->szSetting, "Status")) { + if (!db_get_b(hContact, "CList", "Hidden", 0)) { + if (db_get_b(NULL, "CList", "HideOffline", SETTING_HIDEOFFLINE_DEFAULT)) { + // User's state is changing, and we are hideOffline-ing + if (cws->value.wVal == ID_STATUS_OFFLINE) { + cli.pfnChangeContactIcon(hContact, cli.pfnIconFromStatusMode(cws->szModule, cws->value.wVal, hContact), 0); + CallService(MS_CLUI_CONTACTDELETED, hContact, 0); + return 0; } - cli.pfnChangeContactIcon(hContact, cli.pfnIconFromStatusMode(cws->szModule, cws->value.wVal, hContact), 0); + cli.pfnChangeContactIcon(hContact, cli.pfnIconFromStatusMode(cws->szModule, cws->value.wVal, hContact), 1); } - } - else { - mir_free(dbv.pszVal); - return 0; + cli.pfnChangeContactIcon(hContact, cli.pfnIconFromStatusMode(cws->szModule, cws->value.wVal, hContact), 0); } } + + return 0; } if (!strcmp(cws->szModule, "CList")) { @@ -207,8 +222,15 @@ int ContactSettingChanged(WPARAM hContact, LPARAM lParam) else CallService(MS_CLUI_CONTACTDELETED, hContact, 0); } - if (!strcmp(cws->szSetting, "MyHandle")) - cli.pfnInvalidateDisplayNameCacheEntry(hContact); + else if (!strcmp(cws->szSetting, "MyHandle")) { + ClcCacheEntry *pdnce = cli.pfnGetCacheEntry(hContact); + replaceStrT(pdnce->tszName, NULL); + cli.pfnCheckCacheItem(pdnce); + } + else if (!strcmp(cws->szSetting, "Group")) { + ClcCacheEntry *pdnce = cli.pfnGetCacheEntry(hContact); + Dbwcs2tstr(cws, pdnce->tszGroup); + } } if (!strcmp(cws->szModule, "Protocol")) { @@ -219,15 +241,8 @@ int ContactSettingChanged(WPARAM hContact, LPARAM lParam) else szProto = cws->value.pszVal; cli.pfnChangeContactIcon(hContact, - cli.pfnIconFromStatusMode(szProto, - szProto == NULL ? ID_STATUS_OFFLINE : db_get_w(hContact, szProto, "Status", - ID_STATUS_OFFLINE), hContact), 0); + cli.pfnIconFromStatusMode(szProto, szProto == NULL ? ID_STATUS_OFFLINE : db_get_w(hContact, szProto, "Status", ID_STATUS_OFFLINE), hContact), 0); } } - - // Clean up - if (dbv.pszVal) - mir_free(dbv.pszVal); - return 0; } -- cgit v1.2.3