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; }
KviSharedFile * KviSharedFilesManager::addSharedFile(const QString & szName, const QString & szAbsPath, const QString & szMask, int timeoutInSecs) { QFileInfo inf(szAbsPath); if(inf.exists() && inf.isFile() && inf.isReadable() && (inf.size() > 0)) { // First find the list KviSharedFileList * l = m_pSharedListDict->find(szName); if(!l) { l = new KviSharedFileList; l->setAutoDelete(true); m_pSharedListDict->replace(szName, l); } // Now insert KviSharedFile * o = new KviSharedFile(szName, szAbsPath, szMask, timeoutInSecs > 0 ? (((int)(time(nullptr))) + timeoutInSecs) : 0, inf.size()); doInsert(l, o); if(((int)o->expireTime()) > 0) { if(!m_pCleanupTimer->isActive()) m_pCleanupTimer->start(60000); } emit sharedFileAdded(o); return o; } else { qDebug("File %s unreadable: can't add offer", szAbsPath.toUtf8().data()); return nullptr; } }
bool KviSharedFilesManager::removeSharedFile(const QString &szName,KviSharedFile * off) { KviSharedFileList * l = m_pSharedListDict->find(szName); if(!l)return false; for(KviSharedFile * o = l->first();o;o = l->next()) { if(off == o) { QString save = szName; // <-- szName MAY Be a pointer to o->name() l->removeRef(o); if(l->count() == 0)m_pSharedListDict->remove(save); emit sharedFileRemoved(off); return true; } } return false; }
void KviSharedFilesManager::addSharedFile(KviSharedFile * f) { // First find the list KviSharedFileList * l = m_pSharedListDict->find(f->name()); if(!l) { l = new KviSharedFileList; l->setAutoDelete(true); m_pSharedListDict->replace(f->name(),l); } doInsert(l,f); if(((int)f->expireTime()) > 0) { if(!m_pCleanupTimer->isActive())m_pCleanupTimer->start(60000); } emit sharedFileAdded(f); }
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; }