KviSharedFile * KviSharedFilesManager::lookupSharedFile(const QString & szName, KviIrcMask * mask, unsigned int uFileSize) { KviSharedFileList * l = m_pSharedListDict->find(szName); if(!l) return nullptr; for(KviSharedFile * o = l->first(); o; o = l->next()) { bool bMatch; if(mask) { KviIrcMask umask(o->userMask()); bMatch = mask->matchedBy(umask); } else bMatch = KviQString::equalCS(o->userMask(), "*!*@*"); if(bMatch) { if(uFileSize > 0) { if(uFileSize == o->fileSize()) return o; } else return o; } } return nullptr; }
void KviSharedFilesManager::save(const QString & szFilename) { KviConfigurationFile cfg(szFilename, KviConfigurationFile::Write); cfg.clear(); cfg.setGroup("PermanentFileOffers"); KviPointerHashTableIterator<QString, KviSharedFileList> it(*m_pSharedListDict); int i = 0; while(KviSharedFileList * pList = it.current()) { for(KviSharedFile * pFile = pList->first(); pFile; pFile = pList->next()) { if(((int)(pFile->expireTime())) == 0) { QString szTmp; szTmp = QString("%1FName").arg(i); cfg.writeEntry(szTmp, it.currentKey()); szTmp = QString("%1FilePath").arg(i); cfg.writeEntry(szTmp, pFile->absFilePath()); szTmp = QString("%1UserMask").arg(i); cfg.writeEntry(szTmp, pFile->userMask()); ++i; } } ++it; } cfg.writeEntry("NEntries", i); }
bool KviSharedFilesManager::removeSharedFile(const QString &szName,const QString &szMask,unsigned int uFileSize) { KviSharedFileList * l = m_pSharedListDict->find(szName); if(!l)return false; for(KviSharedFile * o = l->first();o;o = l->next()) { if(KviQString::equalCI(szMask,o->userMask())) { bool bMatch = uFileSize > 0 ? uFileSize == o->fileSize() : true; if(bMatch) { QString save = szName; // <-- szName MAY Be a pointer to o->name() l->removeRef(o); if(l->count() == 0)m_pSharedListDict->remove(save); emit sharedFileRemoved(o); return true; } } } return false; }