summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAnne Jan Brouwer <brouwer@annejan.com>2019-09-04 13:07:42 +0200
committerAnne Jan Brouwer <brouwer@annejan.com>2019-09-04 13:07:42 +0200
commite7f6939b0ef9c44d21abec8999037929fb19a615 (patch)
tree2181489d7b317384b4609d3e51a97fc09406be80 /src
parent30ab999f54b8f142efe0d006fc63aaeec5d47834 (diff)
parent9c167f2befcd97351a2119dcc8e2e9e1152cd745 (diff)
Merge branch 'feature/renameEntry' of https://github.com/Noettore/QtPass into Noettore-feature/renameEntry
Diffstat (limited to 'src')
-rw-r--r--src/mainwindow.cpp49
-rw-r--r--src/mainwindow.h2
2 files changed, 51 insertions, 0 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 166fc9d5..c794a521 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -916,6 +916,13 @@ void MainWindow::showContextMenu(const QPoint &pos) {
// SLOT(copyPasswordToClipboard()));
// }
contextMenu.addSeparator();
+ if (fileOrFolder.isDir()) {
+ QAction *renameFolder = contextMenu.addAction(tr("Rename folder"));
+ connect(renameFolder, &QAction::triggered, this, &MainWindow::renameFolder);
+ } else if (fileOrFolder.isFile()) {
+ QAction *renamePassword = contextMenu.addAction(tr("Rename password"));
+ connect(renamePassword, &QAction::triggered, this, &MainWindow::renamePassword);
+ }
QAction *deleteItem = contextMenu.addAction(tr("Delete"));
connect(deleteItem, &QAction::triggered, this, &MainWindow::onDelete);
}
@@ -967,6 +974,27 @@ void MainWindow::addFolder() {
}
/**
+ * @brief MainWindow::renameFolder rename an existing folder
+ */
+void MainWindow::renameFolder() {
+ bool ok;
+ QString srcDir = QDir::cleanPath(Util::getDir(ui->treeView->currentIndex(), false, model, proxyModel));
+ QString srcDirName = QDir(srcDir).dirName();
+ QString newName =
+ QInputDialog::getText(this, tr("Rename file"),
+ tr("Rename Folder To: "),
+ QLineEdit::Normal,
+ srcDirName,
+ &ok);
+ if (!ok || newName.isEmpty())
+ return;
+ QString destDir = srcDir;
+ destDir.replace(srcDir.lastIndexOf(srcDirName), srcDirName.length(), newName);
+ QtPassSettings::getPass()->Move(srcDir, destDir);
+}
+
+
+/**
* @brief MainWindow::editPassword read password and open edit window via
* MainWindow::onEdit()
*/
@@ -979,6 +1007,27 @@ void MainWindow::editPassword(const QString &file) {
}
/**
+ * @brief MainWindow::renamePassword rename an existing password
+ */
+void MainWindow::renamePassword() {
+ bool ok;
+ QString file = getFile(ui->treeView->currentIndex(), false);
+ QString fileName = QFileInfo(file).baseName();
+ QString newName =
+ QInputDialog::getText(this, tr("Rename file"),
+ tr("Rename File To: "),
+ QLineEdit::Normal,
+ fileName,
+ &ok);
+ if (!ok || newName.isEmpty())
+ return;
+ QString newFile = file;
+ newFile.replace(file.lastIndexOf(fileName), fileName.length(), newName);
+ newFile.replace(QRegExp("\\.gpg$"), "");
+ QtPassSettings::getPass()->Move(file, newFile);
+}
+
+/**
* @brief MainWindow::clearTemplateWidgets empty the template widget fields in
* the UI
*/
diff --git a/src/mainwindow.h b/src/mainwindow.h
index f8c5be7d..32820e77 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -105,7 +105,9 @@ private slots:
void showContextMenu(const QPoint &pos);
void showBrowserContextMenu(const QPoint &pos);
void openFolder();
+ void renameFolder();
void editPassword(const QString &);
+ void renamePassword();
void focusInput();
void copyPasswordFromTreeview();
void passwordFromFileToClipboard(const QString &text);