From 6f498977c5ce208338b742bffcdde1a5f119fc25 Mon Sep 17 00:00:00 2001 From: blacksun Date: Tue, 3 Jan 2017 16:47:39 +0000 Subject: [PATCH] =?UTF-8?q?Bad=20behavior=20fix=20:=20in=20element=20colle?= =?UTF-8?q?ction=20tree,=20when=20user=20drop=20a=20directory=20into=20its?= =?UTF-8?q?elf,=20this=20directory=20is=20copied=20in=20recursive=20way=20?= =?UTF-8?q?infinitely.=20See=20bug=20report=20N=C2=B0=20121?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4831 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- .../elementcollectionhandler.cpp | 22 +++++++++++++++---- .../elementscollectionmodel.cpp | 7 +++--- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/sources/ElementsCollection/elementcollectionhandler.cpp b/sources/ElementsCollection/elementcollectionhandler.cpp index efb69ee2f..b519d28fd 100644 --- a/sources/ElementsCollection/elementcollectionhandler.cpp +++ b/sources/ElementsCollection/elementcollectionhandler.cpp @@ -96,11 +96,25 @@ ElementsLocation ECHSFileToFile::copyDirectory(ElementsLocation &source, Element //Copy all dirs found in source_dir to destination_dir ElementsLocation created_location(created_dir.canonicalPath()); - foreach(QString str, source_dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)) - { + //Used this bool when user drop a folder into itself to avoid infinite recursive creation of the dropped dir + bool copy_itself = false; + if (source_dir == destination_dir) + copy_itself = true; + + foreach(QString str, source_dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)) + { + if (copy_itself) + { + if (source_dir.dirName() == str) + { + copy_itself = false; + continue; + } + } + ElementsLocation sub_source(source.fileSystemPath() + "/" + str); - copyDirectory(sub_source, created_location); - } + copyDirectory(sub_source, created_location); + } //Copy all elements found in source_dir to destination_dir source_dir.setNameFilters(QStringList() << "*.elmt"); diff --git a/sources/ElementsCollection/elementscollectionmodel.cpp b/sources/ElementsCollection/elementscollectionmodel.cpp index 62ea88568..e36304b73 100644 --- a/sources/ElementsCollection/elementscollectionmodel.cpp +++ b/sources/ElementsCollection/elementscollectionmodel.cpp @@ -122,8 +122,8 @@ bool ElementsCollectionModel::canDropMimeData(const QMimeData *data, Qt::DropAct ElementCollectionItem *eci = static_cast(qsi); - if (data->hasFormat("application/x-qet-element-uri") || data->hasFormat("application/x-qet-category-uri")) { - return true; + if (data->hasFormat("application/x-qet-element-uri") || data->hasFormat("application/x-qet-category-uri")) + { //Return false if user try to drop a item from a folder to the same folder ElementsLocation drop_location(data->text()); for (int i=0 ; irowCount() ; i++) @@ -154,7 +154,8 @@ bool ElementsCollectionModel::dropMimeData(const QMimeData *data, Qt::DropAction if (!qsi) qsi = itemFromIndex(parent); - if (qsi->type() == FileElementCollectionItem::Type) { + if (qsi->type() == FileElementCollectionItem::Type) + { FileElementCollectionItem *feci = static_cast(qsi); if (feci->isCommonCollection())