diff options
author | Anne Jan Brouwer <brouwer@annejan.com> | 2015-06-11 14:58:47 +0200 |
---|---|---|
committer | Anne Jan Brouwer <annejan@noprotocol.com> | 2015-06-11 14:58:47 +0200 |
commit | a76bde4806d4f5eca8afffc4600069bc257000f2 (patch) | |
tree | 55e49e49becd88057b71e366df4a43d45c99cba8 /mainwindow.cpp | |
parent | cafda18672cd0b85931f2f8bd2803556547150c9 (diff) |
folder removal added
Diffstat (limited to 'mainwindow.cpp')
-rw-r--r-- | mainwindow.cpp | 62 |
1 files changed, 52 insertions, 10 deletions
diff --git a/mainwindow.cpp b/mainwindow.cpp index 500158e4..88e69854 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -836,18 +836,60 @@ void MainWindow::on_addButton_clicked() */ void MainWindow::on_deleteButton_clicked() { - QString file = getFile(ui->treeView->currentIndex(), usePass); - if (QMessageBox::question(this, tr("Delete password?"), - tr("Are you sure you want to delete %1?").arg(QDir::separator() + file), - QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) { - return; - } - currentAction = DELETE; - if (usePass) { - executePass("rm -f \"" + file + '"'); + QFileInfo fileOrFolder = model.fileInfo(proxyModel.mapToSource(ui->treeView->currentIndex())); + QString file = ""; + + if (fileOrFolder.isFile()) { + file = getFile(ui->treeView->currentIndex(), usePass); + if (QMessageBox::question(this, tr("Delete password?"), + tr("Are you sure you want to delete %1?").arg(QDir::separator() + getFile(ui->treeView->currentIndex(), true)), + QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) { + return; + } + if (usePass) { + currentAction = DELETE; + executePass("rm -f \"" + file + '"'); + } else { + QFile(file).remove(); + } } else { - QFile(file).remove(); + file = getDir(ui->treeView->currentIndex(), false); + if (QMessageBox::question(this, tr("Delete folder?"), + tr("Are you sure you want to delete %1?").arg(QDir::separator() + getDir(ui->treeView->currentIndex(), true)), + QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) { + return; + } + removeDir(file); + } + +} + +/** + * @brief MainWindow::removeDir + * @param dirName + * @return + */ +bool MainWindow::removeDir(const QString & dirName) +{ + bool result = true; + QDir dir(dirName); + + if (dir.exists(dirName)) { + Q_FOREACH(QFileInfo info, dir.entryInfoList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden | QDir::AllDirs | QDir::Files, QDir::DirsFirst)) { + if (info.isDir()) { + result = removeDir(info.absoluteFilePath()); + } + else { + result = QFile::remove(info.absoluteFilePath()); + } + + if (!result) { + return result; + } + } + result = dir.rmdir(dirName); } + return result; } /** |