fixed download from RsCollection dialog

This commit is contained in:
csoler 2024-03-14 22:12:57 +01:00
parent 094c80e046
commit 27f0962654
4 changed files with 54 additions and 7 deletions

View File

@ -238,7 +238,7 @@ void RsCollection::recursCollectColFileInfos(const QDomElement& e,std::vector<Co
void RsCollection::recursAddElements(RsFileTree::DirIndex parent, const DirDetails& dd, FileSearchFlags flags) void RsCollection::recursAddElements(RsFileTree::DirIndex parent, const DirDetails& dd, FileSearchFlags flags)
{ {
if (dd.type == DIR_TYPE_FILE) if (dd.type == DIR_TYPE_FILE)
mFileTree->addFile(parent,dd.name,dd.hash,dd.size); mHashes[dd.hash] = mFileTree->addFile(parent,dd.name,dd.hash,dd.size);
else if (dd.type == DIR_TYPE_DIR) else if (dd.type == DIR_TYPE_DIR)
{ {
RsFileTree::DirIndex new_dir_index = mFileTree->addDirectory(parent,dd.name); RsFileTree::DirIndex new_dir_index = mFileTree->addDirectory(parent,dd.name);
@ -488,6 +488,7 @@ bool RsCollection::save(const QString& fileName) const
bool RsCollection::recursParseXml(QDomDocument& doc,const QDomNode& e,const RsFileTree::DirIndex parent) bool RsCollection::recursParseXml(QDomDocument& doc,const QDomNode& e,const RsFileTree::DirIndex parent)
{ {
mHashes.clear();
QDomNode n = e.firstChild() ; QDomNode n = e.firstChild() ;
#ifdef COLLECTION_DEBUG #ifdef COLLECTION_DEBUG
std::cerr << "Parsing element " << e.tagName().toStdString() << std::endl; std::cerr << "Parsing element " << e.tagName().toStdString() << std::endl;
@ -509,7 +510,7 @@ bool RsCollection::recursParseXml(QDomDocument& doc,const QDomNode& e,const RsFi
std::string name = purifyFileName(ee.attribute(QString("name")), bad_chars_detected).toUtf8().constData() ; std::string name = purifyFileName(ee.attribute(QString("name")), bad_chars_detected).toUtf8().constData() ;
uint64_t size = ee.attribute(QString("size")).toULongLong() ; uint64_t size = ee.attribute(QString("size")).toULongLong() ;
mFileTree->addFile(parent,name,hash,size); mHashes[hash] = mFileTree->addFile(parent,name,hash,size);
#ifdef TO_REMOVE #ifdef TO_REMOVE
mFileTree.addFile(parent,) mFileTree.addFile(parent,)
ColFileInfo newChild ; ColFileInfo newChild ;
@ -551,10 +552,6 @@ bool RsCollection::recursParseXml(QDomDocument& doc,const QDomNode& e,const RsFi
n = n.nextSibling() ; n = n.nextSibling() ;
} }
mHashes.clear();
for(uint64_t i=0;i<mFileTree->numFiles();++i)
mHashes.insert(std::make_pair(mFileTree->fileData(i).hash,i ));
return true; return true;
} }
bool RsCollection::recursExportToXml(QDomDocument& doc,QDomElement& e,const RsFileTree::DirData& dd) const bool RsCollection::recursExportToXml(QDomDocument& doc,QDomElement& e,const RsFileTree::DirData& dd) const

View File

@ -1421,13 +1421,55 @@ void RsCollectionDialog::cancel()
*/ */
void RsCollectionDialog::download() void RsCollectionDialog::download()
{ {
#ifdef TODO_COLLECTION
std::cerr << "Downloading!" << std::endl; std::cerr << "Downloading!" << std::endl;
QString dldir = ui.downloadFolder_LE->text(); QString dldir = ui.downloadFolder_LE->text();
std::cerr << "downloading all these files:" << std::endl; std::cerr << "downloading all these files:" << std::endl;
std::function<void(RsFileTree::DirIndex,const std::string&)> recursDL = [&](RsFileTree::DirIndex index,const std::string& path)
{
const auto& dirdata(mCollection->fileTree().directoryData(index));
RsCollectionModel::EntryIndex e;
for(uint32_t i=0;i<dirdata.subdirs.size();++i)
{
e.index = dirdata.subdirs[i];
e.is_file = false;
if(!mCollectionModel->isChecked(e))
continue;
const auto& sdd = mCollection->fileTree().directoryData(e.index);
std::string subpath = RsDirUtil::makePath(path,sdd.name);
std::cerr << "Creating subdir " << sdd.name << " to directory " << path << std::endl;
if(!QDir(QApplication::applicationDirPath()).mkpath(QString::fromUtf8(subpath.c_str())))
QMessageBox::warning(NULL,tr("Unable to make path"),tr("Unable to make path:")+"<br> "+QString::fromUtf8(subpath.c_str())) ;
recursDL(dirdata.subdirs[i],subpath);
}
for(uint32_t i=0;i<dirdata.subfiles.size();++i)
{
e.index = dirdata.subfiles[i];
e.is_file = true;
if(!mCollectionModel->isChecked(e))
continue;
std::string subpath = RsDirUtil::makePath(path,dirdata.name);
const auto& f(mCollection->fileTree().fileData(dirdata.subfiles[i]));
std::cerr << "Requesting file " << f.name << " to directory " << path << std::endl;
rsFiles->FileRequest(f.name,f.hash,f.size,path,RS_FILE_REQ_ANONYMOUS_ROUTING,std::list<RsPeerId>());
}
};
recursDL(mCollection->fileTree().root(),dldir.toUtf8().constData());
close();
#ifdef TO_REMOVE
while ((item = *itemIterator) != NULL) { while ((item = *itemIterator) != NULL) {
++itemIterator; ++itemIterator;

View File

@ -438,6 +438,13 @@ QVariant RsCollectionModel::decorationRole(const EntryIndex& i,int col) const
return QVariant(); return QVariant();
} }
bool RsCollectionModel::isChecked(EntryIndex i)
{
if(i.is_file)
return mFileInfos[i.index].is_checked;
else
return mDirInfos[i.index].check_state != DirCheckState::UNSELECTED;
}
void RsCollectionModel::notifyFilesBeingHashed(const std::list<RsFileHash>& files) void RsCollectionModel::notifyFilesBeingHashed(const std::list<RsFileHash>& files)
{ {
mFilesBeingHashed.insert(files.begin(),files.end()); mFilesBeingHashed.insert(files.begin(),files.end());

View File

@ -50,6 +50,7 @@ class RsCollectionModel: public QAbstractItemModel
void notifyFilesBeingHashed(const std::list<RsFileHash>& files); void notifyFilesBeingHashed(const std::list<RsFileHash>& files);
void fileHashingFinished(const RsFileHash& hash); void fileHashingFinished(const RsFileHash& hash);
bool isChecked(EntryIndex);
signals: signals:
void sizesChanged(); // tells that the total size of the top level dir has changed (due to selection) void sizesChanged(); // tells that the total size of the top level dir has changed (due to selection)