diff --git a/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp b/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp index c0a50dd51..c9f912420 100644 --- a/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp @@ -18,6 +18,33 @@ * * *******************************************************************************/ +#include "TransfersDialog.h" + +#include "gui/notifyqt.h" +#include "gui/RetroShareLink.h" +#include "gui/common/FilesDefs.h" +#include "gui/common/RsCollection.h" +#include "gui/common/RSTreeView.h" +#include "gui/common/RsUrlHandler.h" +#include "gui/FileTransfer/DetailsDialog.h" +#include "gui/FileTransfer/DLListDelegate.h" +#include "gui/FileTransfer/FileTransferInfoWidget.h" +#include "gui/FileTransfer/SearchDialog.h" +#include "gui/FileTransfer/SharedFilesDialog.h" +#include "gui/FileTransfer/TransferUserNotify.h" +#include "gui/FileTransfer/ULListDelegate.h" +#include "gui/FileTransfer/xprogressbar.h" +#include "gui/settings/rsharesettings.h" +#include "util/misc.h" +#include "util/QtVersion.h" +#include "util/RsFile.h" + +#include "retroshare/rsdisc.h" +#include "retroshare/rsfiles.h" +#include "retroshare/rspeers.h" +#include "retroshare/rsplugin.h" +#include "retroshare/rsturtle.h" + #include #include #include @@ -29,38 +56,10 @@ #include #include -#include -#include -#include -#include - #include #include #include -#include "TransfersDialog.h" -#include -#include "DetailsDialog.h" -#include "DLListDelegate.h" -#include "ULListDelegate.h" -#include "FileTransferInfoWidget.h" -#include -#include -#include "xprogressbar.h" -#include -#include "util/misc.h" -#include -#include "TransferUserNotify.h" -#include "util/QtVersion.h" -#include "util/RsFile.h" - -#include -#include -#include -#include - -#include - /* Images for context menu icons */ #define IMAGE_INFO ":/images/fileinfo.png" #define IMAGE_CANCEL ":/images/delete.png" @@ -142,7 +141,7 @@ public: #endif return mDownloads[entry].peers.size(); } - int columnCount(const QModelIndex &parent = QModelIndex()) const + int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const { return COLUMN_COUNT ; } @@ -250,7 +249,7 @@ public: return createIndex(entry,child.column(),parent_ref) ; } - QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const + QVariant headerData(int section, Qt::Orientation /*orientation*/, int role = Qt::DisplayRole) const { if(role != Qt::DisplayRole) return QVariant(); @@ -279,7 +278,7 @@ public: if(!index.isValid()) return QVariant(); - int coln = index.column() ; + //int coln = index.column() ; switch(role) { @@ -1007,6 +1006,7 @@ TransfersDialog::TransfersDialog(QWidget *parent) connect(collViewAct,SIGNAL(triggered()),this,SLOT(collView())); collOpenAct = new QAction(QIcon(IMAGE_COLLOPEN), tr( "Download from collection file..." ), this ); connect(collOpenAct, SIGNAL(triggered()), this, SLOT(collOpen())); + connect(NotifyQt::getInstance(), SIGNAL(downloadComplete(QString)), this, SLOT(collAutoOpen(QString))); /** Setup the actions for the download header context menu */ showDLSizeAct= new QAction(tr("Size"),this); @@ -2823,6 +2823,35 @@ void TransfersDialog::collOpen() } } +void TransfersDialog::collAutoOpen(const QString &fileHash) +{ + if (Settings->valueFromGroup("Transfer","AutoDLColl").toBool()) + { + RsFileHash hash = RsFileHash(fileHash.toStdString()); + FileInfo info; + if (rsFiles->FileDetails(hash, RS_FILE_HINTS_DOWNLOAD, info)) { + + /* make path for downloaded files */ + if (info.downloadStatus == FT_STATE_COMPLETE) { + std::string path; + path = info.path + "/" + info.fname; + + /* open file with a suitable application */ + QFileInfo qinfo; + qinfo.setFile(QString::fromUtf8(path.c_str())); + if (qinfo.exists()) { + if (qinfo.absoluteFilePath().endsWith(RsCollection::ExtensionString)) { + RsCollection collection; + if (collection.load(qinfo.absoluteFilePath(), false)) { + collection.autoDownloadFiles(); + } + } + } + } + } + } +} + void TransfersDialog::setShowDLSizeColumn (bool show) { ui.downloadList->setColumnHidden(COLUMN_SIZE, !show); } void TransfersDialog::setShowDLCompleteColumn (bool show) { ui.downloadList->setColumnHidden(COLUMN_COMPLETED, !show); } void TransfersDialog::setShowDLDLSpeedColumn (bool show) { ui.downloadList->setColumnHidden(COLUMN_DLSPEED, !show); } diff --git a/retroshare-gui/src/gui/FileTransfer/TransfersDialog.h b/retroshare-gui/src/gui/FileTransfer/TransfersDialog.h index b1e6b4faf..eb39df9b9 100644 --- a/retroshare-gui/src/gui/FileTransfer/TransfersDialog.h +++ b/retroshare-gui/src/gui/FileTransfer/TransfersDialog.h @@ -144,6 +144,7 @@ private slots: void collModif(); void collView(); void collOpen(); + void collAutoOpen(const QString& fileHash); void setShowDLSizeColumn(bool show); void setShowDLCompleteColumn(bool show); diff --git a/retroshare-gui/src/gui/common/RsCollection.cpp b/retroshare-gui/src/gui/common/RsCollection.cpp index b8bb4f7d9..53661fb75 100644 --- a/retroshare-gui/src/gui/common/RsCollection.cpp +++ b/retroshare-gui/src/gui/common/RsCollection.cpp @@ -86,6 +86,46 @@ void RsCollection::downloadFiles() const RsCollectionDialog(_fileName, colFileInfos, false).exec() ; } +void RsCollection::autoDownloadFiles() const +{ + QDomElement docElem = _xml_doc.documentElement(); + + std::vector colFileInfos; + + recursCollectColFileInfos(docElem,colFileInfos,QString(),false); + + QString dlDir = QString::fromUtf8(rsFiles->getDownloadDirectory().c_str()); + + foreach(ColFileInfo colFileInfo, colFileInfos) + { + autoDownloadFiles(colFileInfo, dlDir); + } +} + +void RsCollection::autoDownloadFiles(ColFileInfo colFileInfo, QString dlDir) const +{ + if (!colFileInfo.filename_has_wrong_characters) + { + QString cleanPath = dlDir + colFileInfo.path ; + std::cout << "making directory " << cleanPath.toStdString() << std::endl; + + if(!QDir(QApplication::applicationDirPath()).mkpath(cleanPath)) + std::cerr << "Unable to make path: " + cleanPath.toStdString() << std::endl; + + if (colFileInfo.type==DIR_TYPE_FILE) + rsFiles->FileRequest(colFileInfo.name.toUtf8().constData(), + RsFileHash(colFileInfo.hash.toStdString()), + colFileInfo.size, + cleanPath.toUtf8().constData(), + RS_FILE_REQ_ANONYMOUS_ROUTING, + std::list()); + } + foreach(ColFileInfo colFileInfoChild, colFileInfo.children) + { + autoDownloadFiles(colFileInfoChild, dlDir); + } +} + static QString purifyFileName(const QString& input,bool& bad) { static const QString bad_chars = "/\\\"*:?<>|" ; diff --git a/retroshare-gui/src/gui/common/RsCollection.h b/retroshare-gui/src/gui/common/RsCollection.h index d4764962f..f1a8cb866 100644 --- a/retroshare-gui/src/gui/common/RsCollection.h +++ b/retroshare-gui/src/gui/common/RsCollection.h @@ -85,6 +85,8 @@ public: // Download the content. void downloadFiles() const ; + // Auto Download all the content. + void autoDownloadFiles() const ; qulonglong size(); @@ -102,6 +104,8 @@ private: void recursCollectColFileInfos(const QDomElement&,std::vector& colFileInfos,const QString& current_dir,bool bad_chars_in_parent) const ; // check that the file is a valid rscollection file, and not a lol bomb or some shit like this static bool checkFile(const QString &fileName, bool showError); + // Auto Download recursively. + void autoDownloadFiles(ColFileInfo colFileInfo, QString dlDir) const ; QDomDocument _xml_doc ; QString _fileName ; diff --git a/retroshare-gui/src/gui/common/RsCollectionDialog.cpp b/retroshare-gui/src/gui/common/RsCollectionDialog.cpp index f5ed43c8b..190fcccc5 100644 --- a/retroshare-gui/src/gui/common/RsCollectionDialog.cpp +++ b/retroshare-gui/src/gui/common/RsCollectionDialog.cpp @@ -639,7 +639,7 @@ void RsCollectionDialog::updateSizes() uint64_t total_size = 0 ; uint32_t total_count = 0 ; - for(uint32_t i=0;itopLevelItemCount();++i) + for(int i=0;itopLevelItemCount();++i) { total_size += ui._fileEntriesTW->topLevelItem(i)->data(COLUMN_SIZE ,ROLE_SELSIZE ).toULongLong(); total_count += ui._fileEntriesTW->topLevelItem(i)->data(COLUMN_FILEC,ROLE_SELFILEC).toULongLong(); diff --git a/retroshare-gui/src/gui/settings/TransferPage.cpp b/retroshare-gui/src/gui/settings/TransferPage.cpp index 05259046b..2faa8d5f7 100644 --- a/retroshare-gui/src/gui/settings/TransferPage.cpp +++ b/retroshare-gui/src/gui/settings/TransferPage.cpp @@ -22,12 +22,14 @@ #include "rshare.h" #include "gui/ShareManager.h" +#include "gui/settings/rsharesettings.h" #include "util/misc.h" #include "retroshare/rsiface.h" #include "retroshare/rsfiles.h" #include "retroshare/rspeers.h" +#include #include #include @@ -47,6 +49,7 @@ TransferPage::TransferPage(QWidget * parent, Qt::WindowFlags flags) QObject::connect(ui._filePermDirectDL_CB,SIGNAL(activated(int)),this,SLOT(updateFilePermDirectDL(int))); QObject::connect(ui.incomingButton, SIGNAL(clicked( bool ) ), this , SLOT( setIncomingDirectory() ) ); + QObject::connect(ui.autoDLColl_CB, SIGNAL(toggled(bool)), this, SLOT(updateAutoDLColl())); QObject::connect(ui.partialButton, SIGNAL(clicked( bool ) ), this , SLOT( setPartialsDirectory() ) ); QObject::connect(ui.editShareButton, SIGNAL(clicked()), this, SLOT(editDirectories())); QObject::connect(ui.autoCheckDirectories_CB, SIGNAL(clicked(bool)), this, SLOT(toggleAutoCheckDirectories(bool))); @@ -128,6 +131,7 @@ void TransferPage::load() whileBlocking(ui.autoCheckDirectories_CB)->setChecked(rsFiles->watchEnabled()) ; ; whileBlocking(ui.incomingDir)->setText(QString::fromUtf8(rsFiles->getDownloadDirectory().c_str())); + whileBlocking(ui.autoDLColl_CB)->setChecked(Settings->valueFromGroup("Transfer", "AutoDLColl", false).toBool()); whileBlocking(ui.partialsDir)->setText(QString::fromUtf8(rsFiles->getPartialsDirectory().c_str())); whileBlocking(ui.followSymLinks_CB)->setChecked(rsFiles->followSymLinks()); whileBlocking(ui.ignoreDuplicates_CB)->setChecked(rsFiles->ignoreDuplicates()); @@ -245,6 +249,11 @@ void TransferPage::setIncomingDirectory() whileBlocking(ui.incomingDir)->setText(QString::fromUtf8(rsFiles->getDownloadDirectory().c_str())); } +void TransferPage::updateAutoDLColl() +{ + Settings->setValueToGroup("Transfer", "AutoDLColl", ui.autoDLColl_CB->isChecked()); +} + void TransferPage::setPartialsDirectory() { QString qdir = QFileDialog::getExistingDirectory(this, tr("Set Partials Directory"), "", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); diff --git a/retroshare-gui/src/gui/settings/TransferPage.h b/retroshare-gui/src/gui/settings/TransferPage.h index 1f1eca5cd..8f4c8f0dd 100644 --- a/retroshare-gui/src/gui/settings/TransferPage.h +++ b/retroshare-gui/src/gui/settings/TransferPage.h @@ -54,6 +54,7 @@ class TransferPage: public ConfigPage void editDirectories() ; void setIncomingDirectory(); + void updateAutoDLColl(); void setPartialsDirectory(); void toggleAutoCheckDirectories(bool); diff --git a/retroshare-gui/src/gui/settings/TransferPage.ui b/retroshare-gui/src/gui/settings/TransferPage.ui index 2f6dd0dae..04d1d9400 100644 --- a/retroshare-gui/src/gui/settings/TransferPage.ui +++ b/retroshare-gui/src/gui/settings/TransferPage.ui @@ -16,7 +16,7 @@ Shared Directories - + @@ -91,7 +91,7 @@ - + @@ -103,7 +103,7 @@ - + Maximum depth (0=unlimited): @@ -122,7 +122,7 @@ - + @@ -140,7 +140,7 @@ - + @@ -165,43 +165,57 @@ Incoming Directory - + - - - true - - + + + + + true + + + + + + + + 31 + 31 + + + + + 31 + 31 + + + + Browse + + + + + + + :/images/directoryselect_24x24_shadow.png:/images/directoryselect_24x24_shadow.png + + + + 24 + 24 + + + + + - - - - 31 - 31 - - - - - 31 - 31 - - + - Browse + <html><head/><body><p><span style=" font-weight:600;">WARNING</span>: Some collection may contains a lot of files.</p><p>With this option you cannot check the collection contents before download.</p></body></html> - - - - - :/images/directoryselect_24x24_shadow.png:/images/directoryselect_24x24_shadow.png - - - - 24 - 24 - + Automatically donwload RsCollection file content (Not recommended)