void OptionsDialog::fillTreeWidget(QTreeWidgetItem * p,KviPointerList<OptionsWidgetInstanceEntry> * l,const QString &szGroup,bool bNotContainedOnly) { if(!l)return; OptionsDialogTreeWidgetItem * it; OptionsWidgetInstanceEntry * e; KviPointerList<OptionsWidgetInstanceEntry> tmp; tmp.setAutoDelete(false); for(e = l->first(); e; e = l->next()) { // must be in the correct group // if we want only containers then well.. must be one e->bDoInsert = KviQString::equalCI(szGroup,e->szGroup) && ((!bNotContainedOnly) || e->bIsContainer || e->bIsNotContained); OptionsWidgetInstanceEntry * ee = tmp.first(); int idx = 0; while(ee) { if(ee->iPriority >= e->iPriority)break; idx++; ee = tmp.next(); } tmp.insert(idx,e); } for(e = tmp.first(); e; e = tmp.next()) { if(e->bDoInsert) { if(p)it = new OptionsDialogTreeWidgetItem(p,e); else it = new OptionsDialogTreeWidgetItem(m_pTreeWidget,e); if(!it->m_pOptionsWidget) { it->m_pOptionsWidget = g_pOptionsInstanceManager->getInstance(it->m_pInstanceEntry,m_pWidgetStack); if(it->m_pOptionsWidget) m_pWidgetStack->addWidget(it->m_pOptionsWidget); } } else { it = (OptionsDialogTreeWidgetItem *)p; } if(e->pChildList) { if(e->bIsContainer) { // it's a container: add only eventual not contained children (containers or explicitly marked as not contained) fillTreeWidget(it,e->pChildList,szGroup,true); } else { // it's not a container, add any children fillTreeWidget(it,e->pChildList,szGroup,false); } } } }
void KviAvatarCache::cleanup() { // first do a quick run deleting the avatars really too old KviPointerHashTableIterator<QString,KviAvatarCacheEntry> it(*m_pAvatarDict); kvi_time_t tNow = kvi_unixTime(); KviPointerList<QString> l; l.setAutoDelete(false); KviAvatarCacheEntry * e; while((e = it.current())) { if((tNow - e->tLastAccess) > MAX_UNACCESSED_TIME) { l.append(new QString(it.currentKey())); } ++it; } for(QString *s = l.first();s;s = l.next())m_pAvatarDict->remove(*s); if(m_pAvatarDict->count() < CACHE_GUARD_LEVEL)return; // not done.. need to kill the last accessed :/ it.toFirst(); KviPointerList<KviAvatarCacheEntry> ll; ll.setAutoDelete(true); // here we use the cache entries in another way // szAvatar is the KEY instead of the avatar name while((e = it.current())) { KviAvatarCacheEntry * current = ll.first(); unsigned int idx = 0; while(current) { // if the current is newer than the inserted one // then stop searching and insert it just before if(current->tLastAccess > e->tLastAccess)break; // otherwise the current is older and the inserted // one goes after current = ll.next(); idx++; } KviAvatarCacheEntry * xx = new KviAvatarCacheEntry; xx->szIdString = it.currentKey(); xx->tLastAccess = e->tLastAccess; if(current)ll.insert(idx,xx); else ll.append(xx); ++it; } // the oldest keys are at the beginning int uRemove = ll.count() - CACHE_GUARD_LEVEL; if(uRemove < 1)return; // huh ? // remember that szAvatar contains the key! for(e = ll.first();e && (uRemove > 0);e = ll.next()) { m_pAvatarDict->remove(e->szIdString); uRemove--; } // now we should be ok }