diff --git a/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp b/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp index 0ecc55ac2..58c6092d0 100644 --- a/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp @@ -19,6 +19,33 @@ * Boston, MA 02110-1301, USA. ****************************************************************/ +#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 @@ -30,38 +57,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" @@ -143,7 +142,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 ; } @@ -251,7 +250,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(); @@ -280,7 +279,7 @@ public: if(!index.isValid()) return QVariant(); - int coln = index.column() ; + //int coln = index.column() ; switch(role) { @@ -1005,6 +1004,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 header context menu */ showDLSizeAct= new QAction(tr("Size"),this); @@ -2778,6 +2778,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 51bc205d3..16be8181d 100644 --- a/retroshare-gui/src/gui/FileTransfer/TransfersDialog.h +++ b/retroshare-gui/src/gui/FileTransfer/TransfersDialog.h @@ -146,6 +146,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 e22c9073d..aec20ea13 100644 --- a/retroshare-gui/src/gui/common/RsCollection.cpp +++ b/retroshare-gui/src/gui/common/RsCollection.cpp @@ -89,6 +89,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 87f536033..172d5101e 100644 --- a/retroshare-gui/src/gui/common/RsCollection.h +++ b/retroshare-gui/src/gui/common/RsCollection.h @@ -88,6 +88,8 @@ public: // Download the content. void downloadFiles() const ; + // Auto Download all the content. + void autoDownloadFiles() const ; qulonglong size(); @@ -105,6 +107,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 36e0eb202..4f6ec1c62 100644 --- a/retroshare-gui/src/gui/common/RsCollectionDialog.cpp +++ b/retroshare-gui/src/gui/common/RsCollectionDialog.cpp @@ -642,7 +642,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 7899f8422..553e041a0 100644 --- a/retroshare-gui/src/gui/settings/TransferPage.cpp +++ b/retroshare-gui/src/gui/settings/TransferPage.cpp @@ -23,12 +23,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 @@ -48,6 +50,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))); @@ -129,6 +132,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()); @@ -246,6 +250,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 73826c511..3e28cc919 100644 --- a/retroshare-gui/src/gui/settings/TransferPage.h +++ b/retroshare-gui/src/gui/settings/TransferPage.h @@ -55,6 +55,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 529a6e260..51926d710 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)