add 'Skip' button to overwrite dialog for dirs
authorLukas Hrazky <lukkash@email.cz>
Sat, 24 Jul 2010 20:00:01 +0000 (22:00 +0200)
committerLukas Hrazky <lukkash@email.cz>
Sat, 24 Jul 2010 20:00:01 +0000 (22:00 +0200)
When overwriting directory with another directory, 'No' would mean to
skip it altogether. But it should mean only not to overwrite the files
inside, but move those that are not there. Thats how it works now, and
there is a 'Skip' button that will skip the directory altogether.

Signed-off-by: Lukas Hrazky <lukkash@email.cz>

src/fileoperator.cpp
src/fileoperator.h

index 8a159c7..67c5204 100644 (file)
@@ -226,11 +226,13 @@ void FileOperator::showOverwritePrompt(
     QAbstractButton *noToAllButton = msgBox.addButton(QMessageBox::NoToAll);
     QAbstractButton *abortButton = msgBox.addButton(tr("Abort"), QMessageBox::DestructiveRole);
     QAbstractButton *askButton = 0;
+    QAbstractButton *skipDirButton = 0;
 
     if (dirOverDir) {
         msgBox.setText(tr("Directory %1 already exists. Overwrite the files inside?")
             .arg(FileOperator::shortenPath(fileName)));
         askButton = msgBox.addButton(tr("Ask"), QMessageBox::AcceptRole);
+        skipDirButton = msgBox.addButton(tr("Skip"), QMessageBox::NoRole);
     } else {
         msgBox.setText(tr("File %1 already exists. Overwrite?").arg(FileOperator::shortenPath(fileName)));
     }
@@ -249,6 +251,8 @@ void FileOperator::showOverwritePrompt(
         manipulator->setResponse(KEEP, true);
     } else if (msgBox.clickedButton() == askButton) {
         manipulator->setResponse(NONE, true);
+    } else if (msgBox.clickedButton() == skipDirButton) {
+        manipulator->setResponse(SKIP_DIR);
     }
 }
 
@@ -438,21 +442,33 @@ void FileManipulatorThread::copy(const QFileInfo &file) {
 
     if (abort) return;
 
-    if (response == FileOperator::KEEP) {
-        updateProgress(fileSizeMap[path]);
-        removeExcludeFiles.insert(path);
-        return;
-    }
-
     if (file.isDir()) {
+        // save the overwrite response, because the response variable will get ovewritten in remove(...)
         FileOperator::Response overwriteResponse = response;
 
         if (newFile.exists() && !newFile.isDir()) {
+            // overwriting a file, so check for KEEP and handle it
+            if (response == FileOperator::KEEP) {
+                updateProgress(fileSizeMap[path]);
+                removeExcludeFiles.insert(path);
+                return;
+            }
+
+            // if it should not be kept, remove it and return on failure
             if(!remove(newPath)) {
                 updateProgress(fileSizeMap[path]);
                 return;
             }
+            // create new info since we deleted the file - is it needed?
             newFile = QFileInfo(newPath);
+        } else {
+            // overwriting a directory - response KEEP means to keep the files inside,
+            // SKIP_DIR means to skip the dir completely
+            if (response == FileOperator::SKIP_DIR) {
+                updateProgress(fileSizeMap[path]);
+                removeExcludeFiles.insert(path);
+                return;
+            }
         }
 
         if (!newFile.exists()) {
@@ -460,11 +476,15 @@ void FileManipulatorThread::copy(const QFileInfo &file) {
                 tr("Error creating directory %1."), newPath)
         }
 
+        // we've done the job with the dir, so update progress and recurse into the dir
         updateProgress(1);
         
+        // change the dest for the recursion
         QDir destBackup = dest;
         dest = newPath;
 
+        // and set overwriteAll to the response we got a while ago
+        // because it applies to the files inside the dir
         FileOperator::Response tmpResp = overwriteAll;
         overwriteAll = overwriteResponse;
 
@@ -479,6 +499,12 @@ void FileManipulatorThread::copy(const QFileInfo &file) {
 
         dest = destBackup;
     } else {
+        if (response == FileOperator::KEEP) {
+            updateProgress(fileSizeMap[path]);
+            removeExcludeFiles.insert(path);
+            return;
+        }
+
         SPECIAL_COPY_ERROR_PROMPT(engine.isSequential(), tr("Cannot copy sequential file %1."), path)
 
         if (newFile.exists() && newFile.isDir()) {
@@ -701,15 +727,26 @@ void MoveThread::rename(const QFileInfoList &files, const QDir &dest) {
         QString path = files[i].absoluteFilePath();
         QFSFileEngine engine(path);
         QString newPath = dest.absolutePath() + "/" + files[i].fileName();
+        QFileInfo newFile(newPath);
 
         updateFile(path);
 
-        OVERWRITE_PROMPT(files[i], QFileInfo(newPath))
+        OVERWRITE_PROMPT(files[i], newFile)
 
-        if (response == FileOperator::KEEP) {
-            if (abort) break;
-            updateProgress(1);
-            continue;
+        if (files[i].isDir() && newFile.exists() && newFile.isDir()) {
+            if (response == FileOperator::SKIP_DIR) {
+                if (abort) break;
+                updateProgress(1);
+                removeExcludeFiles.insert(path);
+                continue;
+            }
+        } else {
+            if (response == FileOperator::KEEP) {
+                if (abort) break;
+                updateProgress(1);
+                removeExcludeFiles.insert(path);
+                continue;
+            }
         }
 
         while (!abort && !engine.rename(newPath)) {
@@ -744,7 +781,7 @@ void MoveThread::rename(const QFileInfoList &files, const QDir &dest) {
 
                 overwriteAll = tmpResp;
 
-                ERROR_PROMPT(!engine.rmdir(path, false), tr("Error deleting directory %1."), path)
+                remove(files[i]);
 
                 break;
             // source and target are nonmatching types(file and dir)
index 221eaf8..8a8430d 100644 (file)
@@ -37,7 +37,7 @@ class FileOperator : public QWidget {
 
 public:
     // DONT_ASK_ONCE is a hackish way to avoid asking twice to overwrite the same directory when moving
-    enum Response{NONE, ABORT, RETRY, IGNORE, KEEP, OVERWRITE, DONT_ASK_ONCE};
+    enum Response{NONE, ABORT, RETRY, IGNORE, KEEP, OVERWRITE, SKIP_DIR, DONT_ASK_ONCE};
 
     FileOperator(QWidget *parent = 0);