30 m_destination (destination)
49 if (rd.exec() == QDialog::Accepted)
53 if (location.isDirectory())
55 QDir dir(location.fileSystemPath());
56 dir.removeRecursively();
60 QFile file(location.fileSystemPath());
84 if (!source_dir.exists() || !destination_dir.exists())
return ElementsLocation();
86 QString new_dir_name = rename.isEmpty() ? source_dir.dirName() : rename;
89 if (destination_dir.mkdir(new_dir_name))
92 QDir created_dir(destination_dir.canonicalPath() +
"/" + new_dir_name);
95 QFile::copy(source_dir.canonicalPath() +
"/qet_directory", created_dir.canonicalPath() +
"/qet_directory");
100 bool copy_itself =
false;
101 if (source_dir == destination_dir)
104 foreach(QString str, source_dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name))
108 if (source_dir.dirName() == str)
120 source_dir.setNameFilters(QStringList() <<
"*.elmt");
121 foreach(QString str, source_dir.entryList(QDir::Files | QDir::NoDotAndDotDot, QDir::Name))
127 return created_location;
135 QString new_elmt_name = rename.isEmpty() ? source.
fileName() : rename;
143 extern Q_CORE_EXPORT
int qt_ntfs_permission_lookup;
144 qt_ntfs_permission_lookup++;
146 if (!file.isWritable()) {
147 if (!file.setPermissions(file.permissions() | QFileDevice::WriteUser)) {
148 qDebug() <<
"Failed to change file permission of : " << QFileInfo(file).canonicalFilePath() \
149 <<
" in ECHSFileToFile::copyElement";
152 qt_ntfs_permission_lookup--;
171 if (location.exist())
174 if (rd.exec() == QDialog::Accepted)
178 if (location.isDirectory())
180 QDir dir(location.fileSystemPath());
181 dir.removeRecursively();
185 QFile file(location.fileSystemPath());
210 QString new_dir_name = rename.isEmpty() ? source.
fileName() : rename;
213 if (destination_dir.mkdir(new_dir_name))
215 QDir created_dir(destination_dir.canonicalPath() +
"/" + new_dir_name);
219 QDomDocument document;
220 QDomElement root = document.createElement(
"qet-directory");
221 document.appendChild(root);
224 QString filepath = created_dir.canonicalPath() +
"/qet_directory";
231 foreach(QString name, directories_names)
239 foreach (QString name, elements_names)
245 return created_location;
255 QString new_element_name = rename.isEmpty() ? source.
fileName() : rename;
258 QDomDocument document;
259 document.appendChild(document.importNode(source.
xml(),
true));
262 QString filepath = destination.
fileSystemPath() +
"/" + new_element_name;
283 if (location.exist())
286 if(rd.exec() == QDialog::Accepted)
347 qDebug() <<
"ElementCollectionHandler::createDir : the prerequisites are not valid. " << parent;
354 if (created_dir.
exist()) {
363 if (parent_dir.mkdir(name)) {
365 QDomDocument document;
366 QDomElement root = document.createElement(
"qet-directory");
367 document.appendChild(root);
368 root.appendChild(name_list.
toXml(document));
370 QString filepath = created_dir.
fileSystemPath() +
"/qet_directory";
372 qDebug() <<
"ElementCollectionHandler::createDir : write qet-directory file failed";
377 qDebug() <<
"ElementCollectionHandler::createDir : error was occurred at creation of new directories in file system. ";
387 qDebug() <<
"ElementCollectionHandler::createDir : error was occurred at creation of new directories in embbeded collection.";
408 if (destination.exist())
return true;
410 QList <QString> names;
419 while (!destination.exist()) {
427 while (!names.isEmpty()) {
429 destination = collection->
copy(source, destination, QString(),
false);
431 if (!destination.exist())
453 QDomDocument document;
454 QDomElement root = document.createElement(
"qet-directory");
455 document.appendChild(root);
456 root.appendChild(name_list.
toXml(document));
460 qDebug() <<
"ElementCollectionHandler::setNames : write qet-directory file failed";
468 QDomDocument document;
469 document.appendChild(document.importNode(location.
xml(),
true));
470 if (document.isNull()) {
471 qDebug() <<
"ElementCollectionHandler::setNames : failed to load xml document from file";
475 QDomElement document_element = document.documentElement();
476 document_element.replaceChild(name_list.
toXml(document), document_element.firstChildElement(
"names"));
482 QDomElement element = location.
xml();
483 QDomDocument document = element.ownerDocument();
484 element.replaceChild(name_list.
toXml(document), element.firstChildElement(
"names"));
QStringList directoriesNames(const QDomElement &parent_element) const
XmlElementCollection::directoriesNames.
QString projectCollectionPath() const
ElementsLocation::projectCollectionPath.
bool importFromProject(QETProject *project, ElementsLocation &location)
ElementCollectionHandler::importFromProject Import the element represented by to the embedded collec...
bool isProject() const
ElementsLocation::isProject.
NamesList nameList()
ElementsLocation::nameList.
ElementsLocation copyDirectory(ElementsLocation &source, ElementsLocation &destination, const QString &rename=QString())
ElementsLocation copy(ElementsLocation &source, ElementsLocation &destination, const QString &rename=QString(), bool deep_copy=true)
XmlElementCollection::copy Copy the content represented by source (an element or a directory) to dest...
The ECHSFileToFile class Manage the copy of directory or element from a file system collection to ano...
ElementsLocation copy(ElementsLocation &source, ElementsLocation &destination)
ElementCollectionHandler::copy Copy the content of collection represented by source to the collection...
bool createDir(const QString &path, const QString &name, const NamesList &name_list)
ECHStrategy(ElementsLocation &source, ElementsLocation &destination)
bool isFileSystem() const
ElementsLocation::isFileSystem.
ECHSToXml(ElementsLocation &source, ElementsLocation &destination)
ElementsLocation copy() override
ElementsLocation m_destination
The ECHStrategy class Abstract class for manage copy of directory or element from a collection to ano...
ECHSXmlToFile(ElementsLocation &source, ElementsLocation &destination)
QString fileName() const
ElementLocation::fileName.
ElementsLocation copyElement(ElementsLocation &source, ElementsLocation &destination, const QString &rename=QString())
QDomElement toXml(QDomDocument &, const QHash< QString, QString > &=QHash< QString, QString >()) const
The ECHSXmlToFile class Manage the copy of a directory or element from an xml collection to a file...
QStringList elementsNames(const QDomElement &parent_element) const
XmlElementCollection::elementsNames.
~ElementCollectionHandler()
ElementsLocation createDir(ElementsLocation &parent, const QString &name, const NamesList &name_list)
the target has to be renamed
bool addToPath(const QString &)
ElementsLocation::addToPath Add a string to the actual path of this location.
XmlElementCollection * embeddedElementCollection() const
QETProject::embeddedCollection.
Erase the target content.
ElementsLocation copyDirectory(ElementsLocation &source, ElementsLocation &destination, const QString &rename=QString())
XmlElementCollection * projectCollection() const
ElementsLocation::projectCollection.
QDomElement directory(const QString &path) const
XmlElementCollection::directory.
QString collectionPath(bool protocol=true) const
ElementsLocation copy() override
bool writeXmlFile(QDomDocument &xml_doc, const QString &filepath, QString *error_message=nullptr)
ElementsLocation copyElement(ElementsLocation &source, ElementsLocation &destination, const QString &rename=QString())
QDomElement xml() const
ElementsLocation::xml.
ElementsLocation copy() override
bool exist() const
ElementsLocation::exist.
ElementCollectionHandler()
ElementCollectionHandler::ElementCollectionHandler.
QString fileSystemPath() const
ElementsLocation::fileSystemPath.
bool setNames(ElementsLocation &location, const NamesList &name_list)
ElementCollectionHandler::setNames Set the names stored in as the names of the item represented by l...
The ECHSToXml class Manage the copy of a directory or element from a collection (no matter if the sou...
bool isDirectory() const
ElementsLocation::isDirectory.
virtual ElementsLocation copy()=0
ECHSFileToFile(ElementsLocation &source, ElementsLocation &destination)
ElementsLocation m_source
bool isElement() const
ElementsLocation::isElement.
bool isWritable() const
ElementsLocation::isWritable.
ElementsLocation parent() const
The XmlElementCollection class This class represent a collection of elements stored to xml...