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() void TransfersDialog::pasteLink()
{ {
RSLinkClipboard::process(RetroShareLink::TYPE_FILE); QList<RetroShareLink> links ;
RSLinkClipboard::process(RetroShareLink::TYPE_FILE_TREE);
// 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) 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) ; 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. // parse clipboard for links.
// //
QString text = QApplication::clipboard()->text() ; QString text = QApplication::clipboard()->text() ;
parseText(text, links); parseText(text, links,type);
} }
QString RSLinkClipboard::toString() QString RSLinkClipboard::toString()
@ -1771,26 +1771,18 @@ bool RSLinkClipboard::empty(RetroShareLink::enumType type /* = RetroShareLink::T
return true; 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; QList<RetroShareLink> links;
pasteLinks(links); pasteLinks(links,type);
QList<RetroShareLink> linksToProcess; if (links.isEmpty())
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()) {
return 0; 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(); links.clear();
@ -1805,7 +1797,7 @@ void RSLinkClipboard::parseText(QString text, QList<RetroShareLink> &links)
QString url(text.mid(pos, rx.matchedLength())); QString url(text.mid(pos, rx.matchedLength()));
RetroShareLink link(url); 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: // check that the link is not already in the list:
bool already = false ; 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 // Get the liste of pasted links, either from the internal RS links, or by default
// from the clipboard. // 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. // Produces a list of links with no html structure.
static QString toString() ; 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 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: private:
static void parseClipboard(QList<RetroShareLink> &links) ; static void parseClipboard(QList<RetroShareLink> &links, RetroShareLink::enumType type = RetroShareLink::TYPE_UNKNOWN) ;
}; };
#endif #endif

View File

@ -41,25 +41,21 @@ const QString RsCollection::ExtensionString = QString("rscollection") ;
RsCollection::RsCollection(QObject *parent) RsCollection::RsCollection(QObject *parent)
: QObject(parent), _xml_doc("RsCollection") : QObject(parent), _xml_doc("RsCollection")
{ {
_root = _xml_doc.createElement("RsCollection");
_xml_doc.appendChild(_root);
} }
RsCollection::RsCollection(const FileTree& fr) RsCollection::RsCollection(const FileTree& fr)
: _xml_doc("RsCollection") : _xml_doc("RsCollection")
{ {
QDomElement root = _xml_doc.createElement("RsCollection"); recursAddElements(_xml_doc,fr,0,_root) ;
_xml_doc.appendChild(root);
recursAddElements(_xml_doc,fr,0,root) ;
} }
RsCollection::RsCollection(const std::vector<DirDetails>& file_infos, QObject *parent) RsCollection::RsCollection(const std::vector<DirDetails>& file_infos, QObject *parent)
: QObject(parent), _xml_doc("RsCollection") : 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) 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() RsCollection::~RsCollection()
@ -96,6 +92,21 @@ static QString purifyFileName(const QString& input,bool& bad)
return output ; 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 void RsCollection::recursCollectColFileInfos(const QDomElement& e,std::vector<ColFileInfo>& colFileInfos,const QString& current_path, bool bad_chars_in_parent) const
{ {
QDomNode n = e.firstChild() ; 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("sha1"),QString::fromStdString(subfiles[i].hash.toStdString())) ;
f.setAttribute(QString("size"),QString::number(subfiles[i].size)) ; 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); RsCollection(const FileTree& fr);
virtual ~RsCollection() ; virtual ~RsCollection() ;
void merge_in(const QString& fname,uint64_t size,const RsFileHash& hash) ;
void merge_in(const FileTree& tree) ;
static const QString ExtensionString ; static const QString ExtensionString ;
// Loads file from disk. // Loads file from disk.
bool load(QWidget *parent); bool load(QWidget *parent);
bool load(const QString& fileName, bool showError = true); bool load(const QString& fileName, bool showError = true);
@ -108,6 +109,7 @@ private:
QDomDocument _xml_doc ; QDomDocument _xml_doc ;
QString _fileName ; QString _fileName ;
bool _saved; bool _saved;
QDomElement _root ;
friend class RsCollectionDialog ; friend class RsCollectionDialog ;
}; };