make possible to download an entire found directory from search dialog

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1684 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
alexandrut 2009-09-25 12:17:28 +00:00
parent d59e85efa5
commit b715d07708
2 changed files with 68 additions and 16 deletions

View File

@ -230,7 +230,6 @@ void SearchDialog::searchtableWidgetCostumPopupMenu( QPoint point )
contextMnu->exec( mevent->globalPos() );
}
void SearchDialog::download()
{
/* should also be able to handle multi-selection */
@ -244,19 +243,24 @@ void SearchDialog::download()
// call the download
if (item->text(SR_ID_COL) != "Local")
{
std::cerr << "SearchDialog::download() Calling File Request";
std::cerr << std::endl;
std::list<std::string> srcIds;
srcIds.push_back(item->text(SR_UID_COL).toStdString()) ;
if (!item->childCount()) {
std::cerr << "SearchDialog::download() Calling File Request";
std::cerr << std::endl;
std::list<std::string> srcIds;
srcIds.push_back(item->text(SR_UID_COL).toStdString()) ;
rsFiles -> FileRequest((item->text(SR_NAME_COL)).toStdString(),
(item->text(SR_HASH_COL)).toStdString(),
(item->text(SR_REALSIZE_COL)).toInt(),
"", 0, srcIds);
rsFiles -> FileRequest((item->text(SR_NAME_COL)).toStdString(),
(item->text(SR_HASH_COL)).toStdString(),
(item->text(SR_REALSIZE_COL)).toInt(),
"", 0, srcIds);
std::cout << "isuing file request from search dialog: -" << (item->text(SR_NAME_COL)).toStdString() << "-" << (item->text(SR_HASH_COL)).toStdString() << "-" << (item->text(SR_REALSIZE_COL)).toInt() << "-ids=" ;
for(std::list<std::string>::const_iterator it(srcIds.begin());it!=srcIds.end();++it)
std::cout << *it << "-" << std::endl ;
std::cout << "isuing file request from search dialog: -" << (item->text(SR_NAME_COL)).toStdString() << "-" << (item->text(SR_HASH_COL)).toStdString() << "-" << (item->text(SR_REALSIZE_COL)).toInt() << "-ids=" ;
for(std::list<std::string>::const_iterator it(srcIds.begin());it!=srcIds.end();++it)
std::cout << *it << "-" << std::endl ;
} else {
// we have a folder
downloadDirectory(item, tr(""));
}
}
else
{
@ -269,6 +273,53 @@ void SearchDialog::download()
}
}
void SearchDialog::downloadDirectory(const QTreeWidgetItem *item, const QString &base)
{
if (!item->childCount()) {
std::list<std::string> srcIds;
srcIds.push_back(item->text(SR_UID_COL).toStdString());
QString path = QString::fromStdString(rsFiles->getDownloadDirectory())
+ tr("/") + base + tr("/");
QString cleanPath = QDir::cleanPath(path);
rsFiles->FileRequest(item->text(SR_NAME_COL).toStdString(),
item->text(SR_HASH_COL).toStdString(),
item->text(SR_REALSIZE_COL).toInt(),
cleanPath.toStdString(), 0, srcIds);
std::cout << "SearchDialog::downloadDirectory(): "\
"issuing file request from search dialog: -"
<< (item->text(SR_NAME_COL)).toStdString()
<< "-" << (item->text(SR_HASH_COL)).toStdString()
<< "-" << (item->text(SR_REALSIZE_COL)).toInt()
<< "-ids=" ;
for(std::list<std::string>::const_iterator it(srcIds.begin());
it!=srcIds.end();++it)
std::cout << *it << "-" << std::endl ;
} else {
QDir dwlDir(QString::fromStdString(rsFiles->getDownloadDirectory()));
QString path;
if (base == tr(""))
path = item->text(SR_NAME_COL);
else
path = base + tr("/") + item->text(SR_NAME_COL);
QString cleanPath = QDir::cleanPath(path);
// create this folder in download path
if (!dwlDir.mkpath(cleanPath)) {
std::cerr << "SearchDialog::downloadDirectory() - can't create "
<< cleanPath.toStdString() << " directory" << std::endl;
return;
}
// recursive call for every child - file or folder
for (int i = 0, cnt = item->childCount(); i < cnt; i++) {
QTreeWidgetItem *child = item->child(i);
downloadDirectory(child, path);
}
}
}
void SearchDialog::broadcastonchannel()
{

View File

@ -91,6 +91,7 @@ private:
void insertFile(const std::string& txt,qulonglong searchId, const FileDetail& file) ;
void insertDirectory(const std::string &txt, qulonglong searchId, const DirDetails &dir, QTreeWidgetItem *item);
void setIconAndType(QTreeWidgetItem *item, QString &ext);
void downloadDirectory(const QTreeWidgetItem *item, const QString &base);
/** the advanced search dialog instance */