download of whole directory from gui

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1387 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
alexandrut 2009-07-17 20:07:43 +00:00
parent 8a1ae827b9
commit 48df36f6d0
2 changed files with 37 additions and 1 deletions

View File

@ -765,11 +765,46 @@ void RemoteDirModel::downloadSelected(QModelIndexList list)
/* if it is a dir, copy all files included*/
else if (details.type == DIR_TYPE_DIR)
{
size_t prefixLen = details.path.rfind(details.name);
if (prefixLen < 0) continue;
downloadDirectory(details, prefixLen);
}
}
}
/* recursively download a directory */
void RemoteDirModel::downloadDirectory(const DirDetails & dirDetails, int prefixLen)
{
if (dirDetails.type & DIR_TYPE_FILE)
{
std::list<std::string> srcIds;
QString cleanPath = QDir::cleanPath((rsFiles->getDownloadDirectory() + "/" + dirDetails.path.substr(prefixLen)).c_str());
srcIds.push_back(dirDetails.id);
rsFiles->FileRequest(dirDetails.name, dirDetails.hash, dirDetails.count, cleanPath.toStdString(), 0, srcIds);
}
else if (dirDetails.type & DIR_TYPE_DIR)
{
std::list<DirStub>::const_iterator it;
QDir dwlDir(rsFiles->getDownloadDirectory().c_str());
QString cleanPath = QDir::cleanPath(QString(dirDetails.path.c_str()).right(dirDetails.path.length() - prefixLen));
if (!dwlDir.mkpath(cleanPath)) return;
for (it = dirDetails.children.begin(); it != dirDetails.children.end(); it++)
{
if (!it->ref) continue;
DirDetails subDirDetails;
uint32_t flags = DIR_FLAGS_CHILDREN | DIR_FLAGS_REMOTE;
if (!rsFiles->RequestDirDetails(it->ref, subDirDetails, flags)) continue;
downloadDirectory(subDirDetails, prefixLen);
}
}
}
void RemoteDirModel::getDirDetailsFromSelect (QModelIndexList list, std::vector <DirDetails>& dirVec)
{
dirVec.clear();

View File

@ -69,6 +69,7 @@ virtual QStringList mimeTypes () const;
private:
void update (const QModelIndex &index );
void treeStyle();
void downloadDirectory(const DirDetails & details, int prefixLen);
QIcon categoryIcon;
QIcon peerIcon;