summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnne Jan Brouwer <annejan@noprotocol.com>2015-06-11 14:58:47 +0200
committerAnne Jan Brouwer <annejan@noprotocol.com>2015-06-11 14:58:47 +0200
commit47df0285a400da977a11c1f2e68dfb7c4e987f63 (patch)
tree55e49e49becd88057b71e366df4a43d45c99cba8
parent03f658b0b9bdec62468227968f9e707f09911272 (diff)
folder removal added
-rw-r--r--README.md1
-rw-r--r--mainwindow.cpp62
-rw-r--r--mainwindow.h1
3 files changed, 53 insertions, 11 deletions
diff --git a/README.md b/README.md
index 2b9f5fd3..51191048 100644
--- a/README.md
+++ b/README.md
@@ -49,7 +49,6 @@ Known issues
* Filtering (searching) breaks the tree/model sometimes
* Starting without a correctly set password-store folder give weird results in the tree view
* On Mac OS X only the gpgtools MacGPG2 version works with passphrase or PIN
-* Deleting folders is broken
Planned features
----------------
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;
}
/**
diff --git a/mainwindow.h b/mainwindow.h
index 886a9482..163e626e 100644
--- a/mainwindow.h
+++ b/mainwindow.h
@@ -131,6 +131,7 @@ private:
void updateProfileBox();
void initTrayIcon();
void destroyTrayIcon();
+ bool removeDir(const QString & dirName);
};
#endif // MAINWINDOW_H