From 29d0fd99991e9deaae5787b4568b407c50630f84 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 11 Mar 2014 19:31:45 +0000 Subject: old nasty perversion with dynamically created lists removed git-svn-id: http://svn.miranda-ng.org/main/trunk@8562 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Clist_modern/src/modern_clistsettings.cpp | 191 +++++++++------------- 1 file changed, 79 insertions(+), 112 deletions(-) (limited to 'plugins/Clist_modern/src/modern_clistsettings.cpp') diff --git a/plugins/Clist_modern/src/modern_clistsettings.cpp b/plugins/Clist_modern/src/modern_clistsettings.cpp index 010b3d5d5a..5960f1c12e 100644 --- a/plugins/Clist_modern/src/modern_clistsettings.cpp +++ b/plugins/Clist_modern/src/modern_clistsettings.cpp @@ -28,98 +28,74 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "hdr/modern_awaymsg.h" void InsertContactIntoTree(MCONTACT hContact,int status); -static ClcCacheEntry *displayNameCache; void CListSettings_FreeCacheItemDataOption( ClcCacheEntry *pDst, DWORD flag ); int PostAutoRebuidMessage(HWND hwnd); static int displayNameCacheSize; +LIST clistCache(50, NumericKeySortT); + BOOL CLM_AUTOREBUILD_WAS_POSTED = FALSE; -SortedList *clistCache = NULL; char *GetProtoForContact(MCONTACT hContact); int GetStatusForContact(MCONTACT hContact,char *szProto); TCHAR *UnknownConctactTranslatedName = NULL; void InvalidateDNCEbyPointer(MCONTACT hContact,ClcCacheEntry *pdnce,int SettingType); -static int handleCompare( void* c1, void* c2 ) -{ - INT_PTR p1, p2; - - ClcCacheEntry *dnce1 = (ClcCacheEntry *)c1; - ClcCacheEntry *dnce2 = (ClcCacheEntry *)c2; - - p1 = (INT_PTR)dnce1->hContact; - p2 = (INT_PTR)dnce2->hContact; - - if ( p1 == p2 ) - return 0; - - return (int)(p1 - p2); -} - void InitCacheAsync(); void UninitCacheAsync(); void InitDisplayNameCache(void) { - int i=0; + int i = 0; InitCacheAsync(); InitAwayMsgModule(); - clistCache = List_Create( 0, 50 ); - clistCache->sortFunc = handleCompare; } void FreeDisplayNameCache() { UninitCacheAsync(); UninitAwayMsgModule(); - if ( clistCache != NULL ) { - for (int i=0; i < clistCache->realCount; i++) { - pcli->pfnFreeCacheItem(( ClcCacheEntry* )clistCache->items[i] ); - mir_free_and_nil( clistCache->items[i] ); - } - List_Destroy( clistCache ); - mir_free(clistCache); - clistCache = NULL; + for (int i = 0; i < clistCache.getCount(); i++) { + pcli->pfnFreeCacheItem(clistCache[i]); + mir_free(clistCache[i]); } + clistCache.destroy(); } ClcCacheEntry* cliGetCacheEntry(MCONTACT hContact) { - if (!clistCache) return NULL; - - int idx; ClcCacheEntry *p; - if (!List_GetIndex( clistCache, &hContact, &idx )) { - if (( p = pcli->pfnCreateCacheItem( hContact )) != NULL ) { - List_Insert( clistCache, p, idx ); - pcli->pfnInvalidateDisplayNameCacheEntry( hContact ); + int idx = clistCache.getIndex((ClcCacheEntry*)&hContact); + if (idx == -1) { + if ((p = pcli->pfnCreateCacheItem(hContact)) != NULL) { + clistCache.insert(p); + pcli->pfnInvalidateDisplayNameCacheEntry(hContact); } } - else p = (ClcCacheEntry*)clistCache->items[idx]; - pcli->pfnCheckCacheItem( p ); + else p = clistCache[idx]; + pcli->pfnCheckCacheItem(p); return p; } void CListSettings_FreeCacheItemData(ClcCacheEntry *pDst) { - CListSettings_FreeCacheItemDataOption( pDst, CCI_ALL); + CListSettings_FreeCacheItemDataOption(pDst, CCI_ALL); } -void CListSettings_FreeCacheItemDataOption( ClcCacheEntry *pDst, DWORD flag ) +void CListSettings_FreeCacheItemDataOption(ClcCacheEntry *pDst, DWORD flag) { if (!pDst) return; - if ( flag & CCI_NAME) + if (flag & CCI_NAME) pDst->freeName(); - if ( flag & CCI_GROUP ) + if (flag & CCI_GROUP) mir_free_and_nil(pDst->tszGroup); - if ( flag & CCI_LINES ) { + if (flag & CCI_LINES) { mir_free_and_nil(pDst->szSecondLineText); mir_free_and_nil(pDst->szThirdLineText); pDst->ssSecondLine.DestroySmileyList(); @@ -130,13 +106,12 @@ void CListSettings_FreeCacheItemDataOption( ClcCacheEntry *pDst, DWORD flag ) int CListSettings_GetCopyFromCache(ClcCacheEntry *pDest, DWORD flag); int CListSettings_SetToCache(ClcCacheEntry *pSrc, DWORD flag); - void CListSettings_CopyCacheItems(ClcCacheEntry *pDst, ClcCacheEntry *pSrc, DWORD flag) { if (!pDst || !pSrc) return; CListSettings_FreeCacheItemDataOption(pDst, flag); - if ( flag & CCI_NAME ) { + if (flag & CCI_NAME) { pDst->isUnknown = pSrc->isUnknown; if (pSrc->isUnknown) pDst->tszName = pSrc->tszName; @@ -144,25 +119,25 @@ void CListSettings_CopyCacheItems(ClcCacheEntry *pDst, ClcCacheEntry *pSrc, DWOR pDst->tszName = mir_tstrdup(pSrc->tszName); } - if ( flag & CCI_GROUP ) pDst->tszGroup = mir_tstrdup(pSrc->tszGroup); - if ( flag & CCI_PROTO ) pDst->m_cache_cszProto = pSrc->m_cache_cszProto; - if ( flag & CCI_STATUS ) pDst->m_cache_nStatus = pSrc->m_cache_nStatus; + if (flag & CCI_GROUP) pDst->tszGroup = mir_tstrdup(pSrc->tszGroup); + if (flag & CCI_PROTO) pDst->m_cache_cszProto = pSrc->m_cache_cszProto; + if (flag & CCI_STATUS) pDst->m_cache_nStatus = pSrc->m_cache_nStatus; - if ( flag & CCI_LINES ) { - mir_free( pDst->szThirdLineText ); - pDst->szThirdLineText = mir_tstrdup( pSrc->szThirdLineText ); + if (flag & CCI_LINES) { + mir_free(pDst->szThirdLineText); + pDst->szThirdLineText = mir_tstrdup(pSrc->szThirdLineText); - mir_free( pDst->szSecondLineText ); - pDst->szSecondLineText = mir_tstrdup( pSrc->szSecondLineText ); + mir_free(pDst->szSecondLineText); + pDst->szSecondLineText = mir_tstrdup(pSrc->szSecondLineText); - pDst->ssThirdLine = pSrc->ssThirdLine; + pDst->ssThirdLine = pSrc->ssThirdLine; pDst->ssSecondLine = pSrc->ssSecondLine; } - if ( flag & CCI_TIME) + if (flag & CCI_TIME) pDst->hTimeZone = pSrc->hTimeZone; - if ( flag & CCI_OTHER) { + if (flag & CCI_OTHER) { pDst->bIsHidden = pSrc->bIsHidden; pDst->m_cache_nNoHiddenOffline = pSrc->m_cache_nNoHiddenOffline; pDst->m_cache_bProtoNotExists = pSrc->m_cache_bProtoNotExists; @@ -203,10 +178,10 @@ int CListSettings_SetToCache(ClcCacheEntry *pSrc, DWORD flag) return 0; } -void cliFreeCacheItem( ClcCacheEntry *p ) +void cliFreeCacheItem(ClcCacheEntry *p) { MCONTACT hContact = p->hContact; - TRACEVAR("cliFreeCacheItem hContact = %d",hContact); + TRACEVAR("cliFreeCacheItem hContact = %d", hContact); p->freeName(); mir_free_and_nil(p->tszGroup); mir_free_and_nil(p->szSecondLineText); @@ -244,12 +219,12 @@ void cliCheckCacheItem(ClcCacheEntry *pdnce) } } - if (pdnce___GetStatus( pdnce ) == 0) //very strange look status sort is broken let always reread status - pdnce___SetStatus( pdnce , GetStatusForContact(pdnce->hContact,pdnce->m_cache_cszProto)); + if (pdnce___GetStatus(pdnce) == 0) //very strange look status sort is broken let always reread status + pdnce___SetStatus(pdnce, GetStatusForContact(pdnce->hContact, pdnce->m_cache_cszProto)); if (pdnce->tszGroup == NULL) { - DBVARIANT dbv = {0}; - if (!db_get_ts(pdnce->hContact,"CList","Group",&dbv)) { + DBVARIANT dbv = { 0 }; + if (!db_get_ts(pdnce->hContact, "CList", "Group", &dbv)) { pdnce->tszGroup = mir_tstrdup(dbv.ptszVal); db_free(&dbv); } @@ -257,24 +232,24 @@ void cliCheckCacheItem(ClcCacheEntry *pdnce) } if (pdnce->bIsHidden == -1) - pdnce->bIsHidden = db_get_b(pdnce->hContact,"CList","Hidden",0); + pdnce->bIsHidden = db_get_b(pdnce->hContact, "CList", "Hidden", 0); pdnce->m_cache_nHiddenSubcontact = db_mc_isSub(pdnce->hContact); if (pdnce->m_cache_nNoHiddenOffline == -1) - pdnce->m_cache_nNoHiddenOffline = db_get_b(pdnce->hContact,"CList","noOffline",0); + pdnce->m_cache_nNoHiddenOffline = db_get_b(pdnce->hContact, "CList", "noOffline", 0); if (pdnce->IdleTS == -1) - pdnce->IdleTS = db_get_dw(pdnce->hContact,pdnce->m_cache_cszProto,"IdleTS",0); + pdnce->IdleTS = db_get_dw(pdnce->hContact, pdnce->m_cache_cszProto, "IdleTS", 0); if (pdnce->ApparentMode == -1) - pdnce->ApparentMode = db_get_w(pdnce->hContact,pdnce->m_cache_cszProto,"ApparentMode",0); + pdnce->ApparentMode = db_get_w(pdnce->hContact, pdnce->m_cache_cszProto, "ApparentMode", 0); if (pdnce->NotOnList == -1) - pdnce->NotOnList = db_get_b(pdnce->hContact,"CList","NotOnList",0); + pdnce->NotOnList = db_get_b(pdnce->hContact, "CList", "NotOnList", 0); if (pdnce->IsExpanded == -1) - pdnce->IsExpanded = db_get_b(pdnce->hContact,"CList","Expanded",0); + pdnce->IsExpanded = db_get_b(pdnce->hContact, "CList", "Expanded", 0); if (pdnce->dwLastMsgTime == 0) { pdnce->dwLastMsgTime = db_get_dw(pdnce->hContact, "CList", "mf_lastmsg", 0); @@ -285,17 +260,10 @@ void cliCheckCacheItem(ClcCacheEntry *pdnce) void IvalidateDisplayNameCache(DWORD mode) { - if ( clistCache != NULL ) - { - int i; - for ( i=0; i < clistCache->realCount; i++) - { - ClcCacheEntry *pdnce = (ClcCacheEntry *)clistCache->items[i]; - if (mode&16) - { - InvalidateDNCEbyPointer(pdnce->hContact,pdnce,16); - } - } + for (int i = 0; i < clistCache.getCount(); i++) { + ClcCacheEntry *pdnce = (ClcCacheEntry *)clistCache[i]; + if (mode & 16) + InvalidateDNCEbyPointer(pdnce->hContact, pdnce, 16); } } @@ -313,7 +281,7 @@ void InvalidateDNCEbyPointer(MCONTACT hContact, ClcCacheEntry *pdnce, int Settin pdnce->ssThirdLine.iMaxSmileyHeight = 0; pdnce->hTimeZone = NULL; pdnce->dwLastMsgTime = 0; - Cache_GetTimezone(NULL,pdnce->hContact); + Cache_GetTimezone(NULL, pdnce->hContact); SettingType &= ~16; } @@ -356,10 +324,10 @@ char *GetContactCachedProtocol(MCONTACT hContact) char* GetProtoForContact(MCONTACT hContact) { - return (char*)CallService(MS_PROTO_GETCONTACTBASEACCOUNT,hContact,0); + return (char*)CallService(MS_PROTO_GETCONTACTBASEACCOUNT, hContact, 0); } -int GetStatusForContact(MCONTACT hContact,char *szProto) +int GetStatusForContact(MCONTACT hContact, char *szProto) { return (szProto) ? (int)(db_get_w(hContact, szProto, "Status", ID_STATUS_OFFLINE)) : ID_STATUS_OFFLINE; } @@ -393,15 +361,14 @@ LBL_Unknown: isUnknown = false; } -int GetContactInfosForSort(MCONTACT hContact,char **Proto,TCHAR **Name,int *Status) +int GetContactInfosForSort(MCONTACT hContact, char **Proto, TCHAR **Name, int *Status) { ClcCacheEntry *cacheEntry = NULL; cacheEntry = pcli->pfnGetCacheEntry(hContact); - if (cacheEntry != NULL) - { + if (cacheEntry != NULL) { if (Proto != NULL) *Proto = cacheEntry->m_cache_cszProto; if (Name != NULL) *Name = cacheEntry->tszName; - if (Status != NULL) *Status = pdnce___GetStatus( cacheEntry ); + if (Status != NULL) *Status = pdnce___GetStatus(cacheEntry); } return (0); }; @@ -411,13 +378,13 @@ int GetContactCachedStatus(MCONTACT hContact) { ClcCacheEntry *cacheEntry = NULL; cacheEntry = pcli->pfnGetCacheEntry(hContact); - return pdnce___GetStatus( cacheEntry ); + return pdnce___GetStatus(cacheEntry); } int ContactAdded(WPARAM hContact, LPARAM lParam) { if (!MirandaExiting()) { - cli_ChangeContactIcon(hContact,pcli->pfnIconFromStatusMode((char*)GetContactCachedProtocol(hContact),ID_STATUS_OFFLINE,hContact),1); ///by FYR + cli_ChangeContactIcon(hContact, pcli->pfnIconFromStatusMode((char*)GetContactCachedProtocol(hContact), ID_STATUS_OFFLINE, hContact), 1); ///by FYR pcli->pfnSortContacts(); } return 0; @@ -425,7 +392,7 @@ int ContactAdded(WPARAM hContact, LPARAM lParam) int ContactSettingChanged(WPARAM hContact, LPARAM lParam) { - if (MirandaExiting() || !pcli || !clistCache || hContact == NULL) + if (MirandaExiting() || !pcli || hContact == NULL) return 0; ClcCacheEntry *pdnce = pcli->pfnGetCacheEntry(hContact); @@ -442,7 +409,7 @@ int ContactSettingChanged(WPARAM hContact, LPARAM lParam) InvalidateDNCEbyPointer(hContact, pdnce, cws->value.type); if (!strcmp(cws->szSetting, "IsSubcontact")) - PostMessage(pcli->hwndContactTree, CLM_AUTOREBUILD, 0, 0); + PostMessage(pcli->hwndContactTree, CLM_AUTOREBUILD, 0, 0); if (!mir_strcmp(cws->szSetting, "Status") || wildcmp(cws->szSetting, "Status?")) { if (!mir_strcmp(cws->szModule, META_PROTO) && mir_strcmp(cws->szSetting, "Status")) { @@ -450,19 +417,19 @@ int ContactSettingChanged(WPARAM hContact, LPARAM lParam) if (pcli->hwndContactTree && g_flag_bOnModulesLoadedCalled) res = PostAutoRebuidMessage(pcli->hwndContactTree); - if ((db_get_w(NULL,"CList","SecondLineType",SETTING_SECONDLINE_TYPE_DEFAULT) == TEXT_STATUS_MESSAGE || db_get_w(NULL,"CList","ThirdLineType",SETTING_THIRDLINE_TYPE_DEFAULT) == TEXT_STATUS_MESSAGE) && pdnce->hContact && pdnce->m_cache_cszProto) + if ((db_get_w(NULL, "CList", "SecondLineType", SETTING_SECONDLINE_TYPE_DEFAULT) == TEXT_STATUS_MESSAGE || db_get_w(NULL, "CList", "ThirdLineType", SETTING_THIRDLINE_TYPE_DEFAULT) == TEXT_STATUS_MESSAGE) && pdnce->hContact && pdnce->m_cache_cszProto) amRequestAwayMsg(hContact); return 0; } if (pdnce->bIsHidden != 1) { - pdnce___SetStatus( pdnce , cws->value.wVal ); //dont use direct set + pdnce___SetStatus(pdnce, cws->value.wVal); //dont use direct set if (cws->value.wVal == ID_STATUS_OFFLINE) if (g_CluiData.bRemoveAwayMessageForOffline) - db_set_s(hContact,"CList","StatusMsg",""); + db_set_s(hContact, "CList", "StatusMsg", ""); - if ((db_get_w(NULL,"CList","SecondLineType",0) == TEXT_STATUS_MESSAGE || db_get_w(NULL,"CList","ThirdLineType",0) == TEXT_STATUS_MESSAGE) && pdnce->hContact && pdnce->m_cache_cszProto) + if ((db_get_w(NULL, "CList", "SecondLineType", 0) == TEXT_STATUS_MESSAGE || db_get_w(NULL, "CList", "ThirdLineType", 0) == TEXT_STATUS_MESSAGE) && pdnce->hContact && pdnce->m_cache_cszProto) amRequestAwayMsg(hContact); pcli->pfnClcBroadcast(INTM_STATUSCHANGED, hContact, 0); @@ -478,37 +445,37 @@ int ContactSettingChanged(WPARAM hContact, LPARAM lParam) } } - if (!strcmp(cws->szModule,"CList")) { + if (!strcmp(cws->szModule, "CList")) { //name is null or (setting is myhandle) - if (!strcmp(cws->szSetting,"Rate")) + if (!strcmp(cws->szSetting, "Rate")) pcli->pfnClcBroadcast(CLM_AUTOREBUILD, 0, 0); - else if (pdnce->tszName == NULL || !strcmp(cws->szSetting,"MyHandle")) - InvalidateDNCEbyPointer(hContact,pdnce,cws->value.type); + else if (pdnce->tszName == NULL || !strcmp(cws->szSetting, "MyHandle")) + InvalidateDNCEbyPointer(hContact, pdnce, cws->value.type); - else if (!strcmp(cws->szSetting,"Group")) - InvalidateDNCEbyPointer(hContact,pdnce,cws->value.type); + else if (!strcmp(cws->szSetting, "Group")) + InvalidateDNCEbyPointer(hContact, pdnce, cws->value.type); - else if (!strcmp(cws->szSetting,"Hidden")) { - InvalidateDNCEbyPointer(hContact,pdnce,cws->value.type); + else if (!strcmp(cws->szSetting, "Hidden")) { + InvalidateDNCEbyPointer(hContact, pdnce, cws->value.type); if (cws->value.type == DBVT_DELETED || cws->value.bVal == 0) { char *szProto = GetContactProto(hContact); - cli_ChangeContactIcon(hContact,pcli->pfnIconFromStatusMode(szProto, - szProto == NULL ? ID_STATUS_OFFLINE : db_get_w(hContact,szProto,"Status",ID_STATUS_OFFLINE), hContact),1); //by FYR + cli_ChangeContactIcon(hContact, pcli->pfnIconFromStatusMode(szProto, + szProto == NULL ? ID_STATUS_OFFLINE : db_get_w(hContact, szProto, "Status", ID_STATUS_OFFLINE), hContact), 1); //by FYR } pcli->pfnClcBroadcast(CLM_AUTOREBUILD, 0, 0); } - else if (!strcmp(cws->szSetting,"noOffline")) { - InvalidateDNCEbyPointer(hContact,pdnce,cws->value.type); + else if (!strcmp(cws->szSetting, "noOffline")) { + InvalidateDNCEbyPointer(hContact, pdnce, cws->value.type); pcli->pfnClcBroadcast(CLM_AUTOREBUILD, 0, 0); } } - else if (!strcmp(cws->szModule,"Protocol")) { - if (!strcmp(cws->szSetting,"p")) { - InvalidateDNCEbyPointer(hContact,pdnce,cws->value.type); + else if (!strcmp(cws->szModule, "Protocol")) { + if (!strcmp(cws->szSetting, "p")) { + InvalidateDNCEbyPointer(hContact, pdnce, cws->value.type); char *szProto = (cws->value.type == DBVT_DELETED) ? NULL : cws->value.pszVal; - cli_ChangeContactIcon(hContact,pcli->pfnIconFromStatusMode(szProto, - szProto == NULL ? ID_STATUS_OFFLINE : db_get_w(hContact,szProto,"Status",ID_STATUS_OFFLINE), hContact), 0); + cli_ChangeContactIcon(hContact, pcli->pfnIconFromStatusMode(szProto, + szProto == NULL ? ID_STATUS_OFFLINE : db_get_w(hContact, szProto, "Status", ID_STATUS_OFFLINE), hContact), 0); } } @@ -518,7 +485,7 @@ int ContactSettingChanged(WPARAM hContact, LPARAM lParam) int PostAutoRebuidMessage(HWND hwnd) { if (!CLM_AUTOREBUILD_WAS_POSTED) - CLM_AUTOREBUILD_WAS_POSTED = PostMessage(hwnd,CLM_AUTOREBUILD, 0, 0); + CLM_AUTOREBUILD_WAS_POSTED = PostMessage(hwnd, CLM_AUTOREBUILD, 0, 0); return CLM_AUTOREBUILD_WAS_POSTED; } -- cgit v1.2.3