void RsCollectionFile::recursCollectDLinfos(const QDomElement& e,std::vector<DLinfo>& dlinfos,const QString& current_path, bool bad_chars_in_parent) const { QDomNode n = e.firstChild() ; std::cerr << "Parsing element " << e.tagName().toStdString() << std::endl; while(!n.isNull()) { QDomElement ee = n.toElement(); // try to convert the node to an element. std::cerr << " Seeing child " << ee.tagName().toStdString() << std::endl; if(ee.tagName() == QString("File")) { DLinfo i ; i.hash = ee.attribute(QString("sha1")) ; bool bad_chars_detected = false ; i.name = purifyFileName(ee.attribute(QString("name")), bad_chars_detected) ; i.filename_has_wrong_characters = bad_chars_detected || bad_chars_in_parent ; i.size = ee.attribute(QString("size")).toULongLong() ; i.path = current_path ; dlinfos.push_back(i) ; } else if(ee.tagName() == QString("Directory")) { bool bad_chars_detected = false ; QString cleanDirName = purifyFileName(ee.attribute(QString("name")),bad_chars_detected) ; recursCollectDLinfos(ee,dlinfos,current_path + "/" + cleanDirName, bad_chars_in_parent || bad_chars_detected) ; } n = n.nextSibling() ; } }
/** Process each item to make a new RsCollection item */ void RsCollectionDialog::processItem(QMap<QString, QString> &dirToAdd , int &index , ColFileInfo &parent ) { ColFileInfo newChild; int count = dirToAdd.count(); if (index < count) { QString key=dirToAdd.keys().at(index); bool bad_chars_detected = false; QFileInfo fileInfo=key; QString cleanDirName = purifyFileName(fileInfo.fileName(),bad_chars_detected); newChild.name = cleanDirName; newChild.filename_has_wrong_characters = bad_chars_detected; newChild.size = fileInfo.isDir()? 0: fileInfo.size(); newChild.type = fileInfo.isDir()? DIR_TYPE_DIR: DIR_TYPE_FILE ; if (parent.name != "") { newChild.path = parent.path + "/" + parent.name; } else { newChild.path = parent.path; } dirToAdd[key] = newChild.path + "/" + newChild.name; //Move to next item ++index; if (index < count){ QString newKey = dirToAdd.keys().at(index); while ((dirToAdd.value(newKey) == key) && (index < count)) { processItem(dirToAdd, index, newChild); if (index < count)newKey = dirToAdd.keys().at(index); } } //Save parent when child are processed if (parent.name != "") { parent.children.push_back(newChild); parent.size += newChild.size; } else { _newColFileInfos.push_back(newChild); } }//(index < count) }
/** * @brief RsCollectionDialog::addDir: Add new empty dir to list */ void RsCollectionDialog::makeDir() { QString childName=""; bool ok, badChar, nameOK = false; // Ask for name while (!nameOK) { childName = QInputDialog::getText(this, tr("New Directory") , tr("Enter the new directory's name") , QLineEdit::Normal, childName, &ok); if (ok && !childName.isEmpty()) { childName = purifyFileName(childName, badChar); nameOK = !badChar; if (badChar) { QMessageBox msgBox; msgBox.setText("The name contains bad characters."); msgBox.setInformativeText("Do you want to use the corrected one?\n" + childName); msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Retry | QMessageBox::Cancel); msgBox.setDefaultButton(QMessageBox::Ok); int ret = msgBox.exec(); switch (ret) { case QMessageBox::Ok: nameOK = true; break; case QMessageBox::Retry: break; case QMessageBox::Cancel: return; break; default: // should never be reached break; }//switch (ret) }//if (badChar) } else {//if (ok && !childName.isEmpty()) return; }//if (ok && !childName.isEmpty()) }//while (!nameOK) // Process all selected items int count = ui._fileEntriesTW->selectedItems().count(); int curs = 0; if (count == 0) curs = -1; for (; curs < count; ++curs) { QTreeWidgetItem *item = NULL; if (curs >= 0) { item= ui._fileEntriesTW->selectedItems().at(curs); } else { item = getRootItem(); } if (item) { while (item->data(COLUMN_HASH, ROLE_TYPE).toUInt() != DIR_TYPE_DIR) { item = item->parent();//Only Dir as Parent } ColFileInfo newChild; newChild.name = childName; newChild.filename_has_wrong_characters = false; newChild.size = 0; newChild.type = DIR_TYPE_DIR; newChild.path = item->data(COLUMN_HASH, ROLE_PATH).toString() + "/" + item->data(COLUMN_HASH, ROLE_NAME).toString(); if (item == getRootItem()) newChild.path = ""; _newColFileInfos.push_back(newChild); }//if (item) }//for (; curs < count; ++curs) updateList(); }