void chanFileSystemDockWidget::removeFile() { QList<QTreeWidgetItem*> items = m_fileSystemTree->selectedItems(); std::for_each(items.begin(), items.end(), [this](QTreeWidgetItem* item) { emit removedFile(item->text(0)); //修改硬盘中的数据 QFile().remove(item->data(0, FILE_NAME_KEY).toString()); delete item; }); }
void chanFileSystemDockWidget::removeFolder() { QList<QTreeWidgetItem*> items = m_fileSystemTree->selectedItems(); //跟节点不可以被删除 if (!items.isEmpty() && (m_fileSystemTree->itemAbove(items.front()) == NULL)) { return; } std::for_each(items.begin(), items.end(), [this](QTreeWidgetItem* item) { QList<QTreeWidgetItem*> list = item->takeChildren(); std::for_each(list.begin(), list.end(), [this](QTreeWidgetItem* item) { emit removedFile(item->text(0)); delete item; }); //删除硬盘中的目录 及其子项 QDir(item->data(0, FOLDER_NAME_KEY).toString()).removeRecursively(); delete item; }); }
void MkPath::internalDoThisPath() { if(waitAction || pathList.isEmpty()) return; ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("source: %1, destination: %2, move: %3").arg(pathList.first().source.absoluteFilePath()).arg(pathList.first().destination.absoluteFilePath()).arg(pathList.first().actionType)); #ifdef ULTRACOPIER_PLUGIN_RSYNC if(pathList.first().actionType==ActionType_RmSync) { if(pathList.first().destination.isFile()) { QFile removedFile(pathList.first().destination.absoluteFilePath()); if(!removedFile.remove()) { if(stopIt) return; waitAction=true; ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"Unable to remove the inode: "+pathList.first().destination.absoluteFilePath()+", error: "+removedFile.errorString()); emit errorOnFolder(pathList.first().destination,removedFile.errorString()); return; } } else if(!rmpath(pathList.first().destination.absoluteFilePath())) { if(stopIt) return; waitAction=true; ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"Unable to remove the inode: "+pathList.first().destination.absoluteFilePath()); emit errorOnFolder(pathList.first().destination,tr("Unable to remove")); return; } pathList.removeFirst(); emit firstFolderFinish(); checkIfCanDoTheNext(); return; } #endif doTheDateTransfer=false; if(keepDate) { if(!pathList.first().source.exists()) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"the sources not exists: "+pathList.first().source.absoluteFilePath()); doTheDateTransfer=false; } else if(maxTime>=pathList.first().source.lastModified()) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"the sources is older to copy the time: "+pathList.first().source.absoluteFilePath()+": "+maxTime.toString("dd.MM.yyyy hh:mm:ss.zzz")+">="+pathList.first().source.lastModified().toString("dd.MM.yyyy hh:mm:ss.zzz")); doTheDateTransfer=false; } else { doTheDateTransfer=readFileDateTime(pathList.first().source); /*if(!doTheDateTransfer) { if(stopIt) return; waitAction=true; ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"Unable to get source folder time: "+pathList.first().source.absoluteFilePath()); emit errorOnFolder(pathList.first().source,tr("Unable to get time")); return; }*/ } } if(dir.exists(pathList.first().destination.absoluteFilePath()) && pathList.first().actionType==ActionType_RealMove) pathList.first().actionType=ActionType_MovePath; if(pathList.first().actionType!=ActionType_RealMove) { if(!dir.exists(pathList.first().destination.absoluteFilePath())) if(!dir.mkpath(pathList.first().destination.absoluteFilePath())) { if(!dir.exists(pathList.first().destination.absoluteFilePath())) { if(stopIt) return; waitAction=true; ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"Unable to make the folder: "+pathList.first().destination.absoluteFilePath()); emit errorOnFolder(pathList.first().destination,tr("Unable to create the folder")); return; } } } else { if(!pathList.first().source.exists()) { if(stopIt) return; waitAction=true; ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"The source folder don't exists: "+pathList.first().source.absoluteFilePath()); emit errorOnFolder(pathList.first().destination,tr("The source folder don't exists")); return; } if(!pathList.first().source.isDir())//it's really an error? { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"The source is not a folder: "+pathList.first().source.absoluteFilePath()); /*if(stopIt) return; waitAction=true; emit errorOnFolder(pathList.first().destination,tr("The source is not a folder")); return;*/ } if(pathList.first().destination.absoluteFilePath().startsWith(pathList.first().source.absoluteFilePath()+text_slash)) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"move into it self: "+pathList.first().destination.absoluteFilePath()); int random=rand(); QFileInfo tempFolder=pathList.first().source.absolutePath()+text_slash+QString::number(random); while(tempFolder.exists()) { random=rand(); tempFolder=pathList.first().source.absolutePath()+text_slash+QString::number(random); } if(!dir.rename(pathList.first().source.absoluteFilePath(),tempFolder.absoluteFilePath())) { if(stopIt) return; waitAction=true; ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"Unable to temporary rename the folder: "+pathList.first().destination.absoluteFilePath()); emit errorOnFolder(pathList.first().destination,tr("Unable to temporary rename the folder")); return; } /* http://doc.qt.io/qt-5/qdir.html#rename * On most file systems, rename() fails only if oldName does not exist, or if a file with the new name already exists. if(!dir.mkpath(pathList.first().destination.absolutePath())) { if(!dir.exists(pathList.first().destination.absolutePath())) { if(stopIt) return; waitAction=true; ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"Unable to make the folder: "+pathList.first().destination.absoluteFilePath()); emit errorOnFolder(pathList.first().destination,tr("Unable to create the folder")); return; } }*/ if(!dir.rename(tempFolder.absoluteFilePath(),pathList.first().destination.absoluteFilePath())) { if(stopIt) return; waitAction=true; ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"Unable to do the final real move the folder: "+pathList.first().destination.absoluteFilePath()); emit errorOnFolder(pathList.first().destination,tr("Unable to do the final real move the folder")); return; } } else { /* http://doc.qt.io/qt-5/qdir.html#rename * On most file systems, rename() fails only if oldName does not exist, or if a file with the new name already exists. if(!dir.mkpath(pathList.first().destination.absolutePath())) { if(!dir.exists(pathList.first().destination.absolutePath())) { if(stopIt) return; waitAction=true; ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"Unable to make the folder: "+pathList.first().destination.absoluteFilePath()); emit errorOnFolder(pathList.first().destination,tr("Unable to create the folder")); return; } }*/ if(!dir.rename(pathList.first().source.absoluteFilePath(),pathList.first().destination.absoluteFilePath())) { if(stopIt) return; waitAction=true; ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"Unable to make the folder: from: "+pathList.first().source.absoluteFilePath()+", soruce exists: "+QString::number(QDir(pathList.first().source.absoluteFilePath()).exists())+", to: "+pathList.first().destination.absoluteFilePath()+", destination exist: "+QString::number(QDir(pathList.first().destination.absoluteFilePath()).exists())); emit errorOnFolder(pathList.first().destination,tr("Unable to move the folder")); return; } } } if(doTheDateTransfer) if(!writeFileDateTime(pathList.first().destination)) { if(!pathList.first().destination.exists()) ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"Unable to set destination folder time (not exists): "+pathList.first().destination.absoluteFilePath()); else if(!pathList.first().destination.isDir()) ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"Unable to set destination folder time (not a dir): "+pathList.first().destination.absoluteFilePath()); else ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"Unable to set destination folder time: "+pathList.first().destination.absoluteFilePath()); /*if(stopIt) return; waitAction=true; emit errorOnFolder(pathList.first().source,tr("Unable to set time")); return;*/ } if(doRightTransfer && pathList.first().actionType!=ActionType_RealMove) { QFile source(pathList.first().source.absoluteFilePath()); QFile destination(pathList.first().destination.absoluteFilePath()); if(!destination.setPermissions(source.permissions())) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"Unable to set the right: "+pathList.first().destination.absoluteFilePath()); /*if(stopIt) return; waitAction=true; emit errorOnFolder(pathList.first().source,tr("Unable to set the access-right")); return;*/ } } if(pathList.first().actionType==ActionType_MovePath) { if(!rmpath(pathList.first().source.absoluteFilePath())) { if(stopIt) return; waitAction=true; ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"Unable to remove the source folder: "+pathList.first().destination.absoluteFilePath()); emit errorOnFolder(pathList.first().source,tr("Unable to remove")); return; } } pathList.removeFirst(); emit firstFolderFinish(); checkIfCanDoTheNext(); }
void ProjectDlg::removeFile() { project.removeFile(files->currentText()); emit removedFile(files->currentText()); files->takeItem(files->selectedItem()); }