From 48df36f6d01112233a081f1edd3c14621e4999ef Mon Sep 17 00:00:00 2001 From: alexandrut Date: Fri, 17 Jul 2009 20:07:43 +0000 Subject: [PATCH] download of whole directory from gui git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1387 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- retroshare-gui/src/rsiface/RemoteDirModel.cpp | 37 ++++++++++++++++++- retroshare-gui/src/rsiface/RemoteDirModel.h | 1 + 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/retroshare-gui/src/rsiface/RemoteDirModel.cpp b/retroshare-gui/src/rsiface/RemoteDirModel.cpp index 6cde34ff2..b34a41427 100644 --- a/retroshare-gui/src/rsiface/RemoteDirModel.cpp +++ b/retroshare-gui/src/rsiface/RemoteDirModel.cpp @@ -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 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::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 & dirVec) { dirVec.clear(); diff --git a/retroshare-gui/src/rsiface/RemoteDirModel.h b/retroshare-gui/src/rsiface/RemoteDirModel.h index e780a775e..0bbd80ec7 100644 --- a/retroshare-gui/src/rsiface/RemoteDirModel.h +++ b/retroshare-gui/src/rsiface/RemoteDirModel.h @@ -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;