void DirectoryListingManager::on(QueueManagerListener::ItemRemoved, const QueueItemPtr& qi, bool aFinished) noexcept { if (!qi->isSet(QueueItem::FLAG_USER_LIST)) return; auto u = qi->getSources()[0].getUser(); if (qi->isSet(QueueItem::FLAG_DIRECTORY_DOWNLOAD) && !aFinished) removeDirectoryDownload(u, qi->getTempTarget(), qi->isSet(QueueItem::FLAG_PARTIAL_LIST)); if (qi->isSet(QueueItem::FLAG_CLIENT_VIEW)) { DirectoryListingPtr dl = nullptr; { RLock l(cs); auto p = viewedLists.find(u); if (p == viewedLists.end()) { dcassert(0); return; } dl = p->second; } dl->onListRemovedQueue(qi->getTarget(), qi->getTempTarget(), aFinished); bool closing = (dl->getClosing() || !dl->hasCompletedDownloads()); if (!aFinished && !dl->hasDownloads() && closing) { removeList(u); } } }
void DirectoryListingManager::on(QueueManagerListener::PartialListFinished, const HintedUser& aUser, const string& aXML, const string& aBase) noexcept { if (aXML.empty()) return; DirectoryListingPtr dl; { RLock l(cs); auto p = viewedLists.find(aUser.user); if (p != viewedLists.end() && p->second->getPartialList()) { dl = p->second; } else { return; } } if (dl->hasCompletedDownloads()) { dl->addHubUrlChangeTask(aUser.hint); dl->addPartialListTask(aXML, aBase, false, true, [=] { dl->setActive(); }); } else { fire(DirectoryListingManagerListener::OpenListing(), dl, aBase, aXML); } }
void DirectoryListingManager::on(QueueManagerListener::ItemFinished, const QueueItemPtr& qi, const string& dir, const HintedUser& aUser, int64_t /*aSpeed*/) noexcept { if (!qi->isSet(QueueItem::FLAG_CLIENT_VIEW) || !qi->isSet(QueueItem::FLAG_USER_LIST)) return; DirectoryListingPtr dl; { RLock l(cs); auto p = viewedLists.find(aUser.user); if (p == viewedLists.end()) { return; } dl = p->second; } if (dl) { dl->setFileName(qi->getListName()); if (dl->hasCompletedDownloads()) { dl->addFullListTask(dir); } else { fire(DirectoryListingManagerListener::OpenListing(), dl, dir, Util::emptyString); } } }