mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-27 08:29:26 -05:00
Merge pull request #1261 from PhenomRetroShare/Add_RsCollAutoDownload
Add RsCollection's content automatically download option.
This commit is contained in:
commit
164a28eb32
@ -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 <QDateTime>
|
||||
#include <QDir>
|
||||
#include <QFileDialog>
|
||||
@ -29,38 +56,10 @@
|
||||
#include <QShortcut>
|
||||
#include <QStandardItemModel>
|
||||
|
||||
#include <gui/common/FilesDefs.h>
|
||||
#include <gui/common/RsCollection.h>
|
||||
#include <gui/common/RsUrlHandler.h>
|
||||
#include <gui/common/RSTreeView.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
#include <math.h>
|
||||
|
||||
#include "TransfersDialog.h"
|
||||
#include <gui/RetroShareLink.h>
|
||||
#include "DetailsDialog.h"
|
||||
#include "DLListDelegate.h"
|
||||
#include "ULListDelegate.h"
|
||||
#include "FileTransferInfoWidget.h"
|
||||
#include <gui/FileTransfer/SearchDialog.h>
|
||||
#include <gui/FileTransfer/SharedFilesDialog.h>
|
||||
#include "xprogressbar.h"
|
||||
#include <gui/settings/rsharesettings.h>
|
||||
#include "util/misc.h"
|
||||
#include <gui/common/RsCollection.h>
|
||||
#include "TransferUserNotify.h"
|
||||
#include "util/QtVersion.h"
|
||||
#include "util/RsFile.h"
|
||||
|
||||
#include <retroshare/rsfiles.h>
|
||||
#include <retroshare/rspeers.h>
|
||||
#include <retroshare/rsdisc.h>
|
||||
#include <retroshare/rsplugin.h>
|
||||
|
||||
#include <retroshare/rsturtle.h>
|
||||
|
||||
/* 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); }
|
||||
|
@ -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);
|
||||
|
@ -86,6 +86,46 @@ void RsCollection::downloadFiles() const
|
||||
RsCollectionDialog(_fileName, colFileInfos, false).exec() ;
|
||||
}
|
||||
|
||||
void RsCollection::autoDownloadFiles() const
|
||||
{
|
||||
QDomElement docElem = _xml_doc.documentElement();
|
||||
|
||||
std::vector<ColFileInfo> 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<RsPeerId>());
|
||||
}
|
||||
foreach(ColFileInfo colFileInfoChild, colFileInfo.children)
|
||||
{
|
||||
autoDownloadFiles(colFileInfoChild, dlDir);
|
||||
}
|
||||
}
|
||||
|
||||
static QString purifyFileName(const QString& input,bool& bad)
|
||||
{
|
||||
static const QString bad_chars = "/\\\"*:?<>|" ;
|
||||
|
@ -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<ColFileInfo>& 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 ;
|
||||
|
@ -639,7 +639,7 @@ void RsCollectionDialog::updateSizes()
|
||||
uint64_t total_size = 0 ;
|
||||
uint32_t total_count = 0 ;
|
||||
|
||||
for(uint32_t i=0;i<ui._fileEntriesTW->topLevelItemCount();++i)
|
||||
for(int i=0;i<ui._fileEntriesTW->topLevelItemCount();++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();
|
||||
|
@ -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 <QCheckBox>
|
||||
#include <QToolTip>
|
||||
|
||||
#include <iostream>
|
||||
@ -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);
|
||||
|
@ -54,6 +54,7 @@ class TransferPage: public ConfigPage
|
||||
|
||||
void editDirectories() ;
|
||||
void setIncomingDirectory();
|
||||
void updateAutoDLColl();
|
||||
void setPartialsDirectory();
|
||||
void toggleAutoCheckDirectories(bool);
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
<property name="title">
|
||||
<string>Shared Directories</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<layout class="QVBoxLayout" name="sharedGBoxVLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="editShareButton">
|
||||
<property name="text">
|
||||
@ -91,7 +91,7 @@
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<layout class="QHBoxLayout" name="ignoreDuplicatesHLayout">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="ignoreDuplicates_CB">
|
||||
<property name="toolTip">
|
||||
@ -103,7 +103,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<widget class="QLabel" name="ignoreDuplicates_L">
|
||||
<property name="text">
|
||||
<string>Maximum depth (0=unlimited):</string>
|
||||
</property>
|
||||
@ -122,7 +122,7 @@
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<layout class="QHBoxLayout" name="suffixesIgnoreListHLayout">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="suffixesIgnoreList_CB">
|
||||
<property name="text">
|
||||
@ -140,7 +140,7 @@
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<layout class="QHBoxLayout" name="prefixesIgnoreListHLayout">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="prefixesIgnoreList_CB">
|
||||
<property name="text">
|
||||
@ -165,43 +165,57 @@
|
||||
<property name="title">
|
||||
<string>Incoming Directory</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<layout class="QVBoxLayout" name="incomingGBoxVLayout">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="incomingDir">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<layout class="QHBoxLayout" name="incomingDirHLayout">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="incomingDir">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="incomingButton">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>31</width>
|
||||
<height>31</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>31</width>
|
||||
<height>31</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Browse</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/directoryselect_24x24_shadow.png</normaloff>:/images/directoryselect_24x24_shadow.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="incomingButton">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>31</width>
|
||||
<height>31</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>31</width>
|
||||
<height>31</height>
|
||||
</size>
|
||||
</property>
|
||||
<widget class="QCheckBox" name="autoDLColl_CB">
|
||||
<property name="toolTip">
|
||||
<string>Browse</string>
|
||||
<string><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></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/directoryselect_24x24_shadow.png</normaloff>:/images/directoryselect_24x24_shadow.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
<string>Automatically donwload RsCollection file content (Not recommended)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
Loading…
Reference in New Issue
Block a user