merge of trees and single files before paste in DL queue so that all use the CollectionEditor

This commit is contained in:
csoler 2017-10-21 17:35:06 +02:00
parent fe516c6b7a
commit 2cfa86620c
5 changed files with 58 additions and 34 deletions

View File

@ -1640,8 +1640,27 @@ void TransfersDialog::updateDetailsDialog()
void TransfersDialog::pasteLink()
{
RSLinkClipboard::process(RetroShareLink::TYPE_FILE);
RSLinkClipboard::process(RetroShareLink::TYPE_FILE_TREE);
QList<RetroShareLink> links ;
// We want to capture and process all links at once here, because we're possibly pasting a large collection of files. So we first
// merge all links into a single RsCollection and then process it.
RsCollection col ;
RSLinkClipboard::pasteLinks(links,RetroShareLink::TYPE_FILE_TREE);
for(QList<RetroShareLink>::const_iterator it(links.begin());it!=links.end();++it)
{
FileTree *ft = FileTree::create((*it).radix().toStdString()) ;
col.merge_in(*ft) ;
}
links.clear();
RSLinkClipboard::pasteLinks(links,RetroShareLink::TYPE_FILE);
for(QList<RetroShareLink>::const_iterator it(links.begin());it!=links.end();++it)
col.merge_in((*it).name(),(*it).size(),RsFileHash((*it).hash().toStdString())) ;
col.downloadFiles();
}
void TransfersDialog::getDLSelectedItems(std::set<RsFileHash> *ids, std::set<int> *rows)

View File

@ -1716,17 +1716,17 @@ void RSLinkClipboard::copyLinks(const QList<RetroShareLink>& links)
QApplication::clipboard()->setText(res) ;
}
void RSLinkClipboard::pasteLinks(QList<RetroShareLink> &links)
void RSLinkClipboard::pasteLinks(QList<RetroShareLink> &links,RetroShareLink::enumType type)
{
return parseClipboard(links);
return parseClipboard(links,type);
}
void RSLinkClipboard::parseClipboard(QList<RetroShareLink> &links)
void RSLinkClipboard::parseClipboard(QList<RetroShareLink> &links,RetroShareLink::enumType type)
{
// parse clipboard for links.
//
QString text = QApplication::clipboard()->text() ;
parseText(text, links);
parseText(text, links,type);
}
QString RSLinkClipboard::toString()
@ -1771,26 +1771,18 @@ bool RSLinkClipboard::empty(RetroShareLink::enumType type /* = RetroShareLink::T
return true;
}
/*static*/ int RSLinkClipboard::process(RetroShareLink::enumType type /* = RetroShareLink::TYPE_UNKNOWN*/, uint flag /* = RSLINK_PROCESS_NOTIFY_ALL*/)
int RSLinkClipboard::process(RetroShareLink::enumType type /* = RetroShareLink::TYPE_UNKNOWN*/, uint flag /* = RSLINK_PROCESS_NOTIFY_ALL*/)
{
QList<RetroShareLink> links;
pasteLinks(links);
pasteLinks(links,type);
QList<RetroShareLink> linksToProcess;
for (int i = 0; i < links.size(); ++i) {
if (links[i].valid() && (type == RetroShareLink::TYPE_UNKNOWN || links[i].type() == type)) {
linksToProcess.append(links[i]);
}
}
if (linksToProcess.isEmpty()) {
if (links.isEmpty())
return 0;
}
return RetroShareLink::process(linksToProcess, flag);
return RetroShareLink::process(links, flag);
}
void RSLinkClipboard::parseText(QString text, QList<RetroShareLink> &links)
void RSLinkClipboard::parseText(QString text, QList<RetroShareLink> &links,RetroShareLink::enumType type )
{
links.clear();
@ -1805,7 +1797,7 @@ void RSLinkClipboard::parseText(QString text, QList<RetroShareLink> &links)
QString url(text.mid(pos, rx.matchedLength()));
RetroShareLink link(url);
if(link.valid())
if(link.valid() && (type == RetroShareLink::TYPE_UNKNOWN || type == link.type()))
{
// check that the link is not already in the list:
bool already = false ;

View File

@ -192,7 +192,7 @@ class RSLinkClipboard
// Get the liste of pasted links, either from the internal RS links, or by default
// from the clipboard.
//
static void pasteLinks(QList<RetroShareLink> &links) ;
static void pasteLinks(QList<RetroShareLink> &links,RetroShareLink::enumType type = RetroShareLink::TYPE_UNKNOWN) ;
// Produces a list of links with no html structure.
static QString toString() ;
@ -215,10 +215,10 @@ class RSLinkClipboard
//
static int process(RetroShareLink::enumType type = RetroShareLink::TYPE_UNKNOWN, uint flag = RSLINK_PROCESS_NOTIFY_ALL);
static void parseText(QString text, QList<RetroShareLink> &links) ;
static void parseText(QString text, QList<RetroShareLink> &links, RetroShareLink::enumType type = RetroShareLink::TYPE_UNKNOWN) ;
private:
static void parseClipboard(QList<RetroShareLink> &links) ;
static void parseClipboard(QList<RetroShareLink> &links, RetroShareLink::enumType type = RetroShareLink::TYPE_UNKNOWN) ;
};
#endif

View File

@ -41,25 +41,21 @@ const QString RsCollection::ExtensionString = QString("rscollection") ;
RsCollection::RsCollection(QObject *parent)
: QObject(parent), _xml_doc("RsCollection")
{
_root = _xml_doc.createElement("RsCollection");
_xml_doc.appendChild(_root);
}
RsCollection::RsCollection(const FileTree& fr)
: _xml_doc("RsCollection")
{
QDomElement root = _xml_doc.createElement("RsCollection");
_xml_doc.appendChild(root);
recursAddElements(_xml_doc,fr,0,root) ;
recursAddElements(_xml_doc,fr,0,_root) ;
}
RsCollection::RsCollection(const std::vector<DirDetails>& file_infos, QObject *parent)
: QObject(parent), _xml_doc("RsCollection")
{
QDomElement root = _xml_doc.createElement("RsCollection");
_xml_doc.appendChild(root);
for(uint32_t i = 0;i<file_infos.size();++i)
recursAddElements(_xml_doc,file_infos[i],root) ;
recursAddElements(_xml_doc,file_infos[i],_root) ;
}
RsCollection::~RsCollection()
@ -96,6 +92,21 @@ static QString purifyFileName(const QString& input,bool& bad)
return output ;
}
void RsCollection::merge_in(const QString& fname,uint64_t size,const RsFileHash& hash)
{
ColFileInfo info ;
info.type = DIR_TYPE_FILE ;
info.name = fname ;
info.size = size ;
info.hash = QString::fromStdString(hash.toStdString()) ;
recursAddElements(_xml_doc,info,_root) ;
}
void RsCollection::merge_in(const FileTree& tree)
{
recursAddElements(_xml_doc,tree,0,_root) ;
}
void RsCollection::recursCollectColFileInfos(const QDomElement& e,std::vector<ColFileInfo>& colFileInfos,const QString& current_path, bool bad_chars_in_parent) const
{
QDomNode n = e.firstChild() ;
@ -235,7 +246,7 @@ void RsCollection::recursAddElements(QDomDocument& doc,const FileTree& ft,uint32
f.setAttribute(QString("sha1"),QString::fromStdString(subfiles[i].hash.toStdString())) ;
f.setAttribute(QString("size"),QString::number(subfiles[i].size)) ;
e.appendChild(f) ;
d.appendChild(f) ;
}
}

View File

@ -68,10 +68,11 @@ public:
RsCollection(const FileTree& fr);
virtual ~RsCollection() ;
void merge_in(const QString& fname,uint64_t size,const RsFileHash& hash) ;
void merge_in(const FileTree& tree) ;
static const QString ExtensionString ;
// Loads file from disk.
bool load(QWidget *parent);
bool load(const QString& fileName, bool showError = true);
@ -108,6 +109,7 @@ private:
QDomDocument _xml_doc ;
QString _fileName ;
bool _saved;
QDomElement _root ;
friend class RsCollectionDialog ;
};