diff options
author | Anne Jan Brouwer <annejan@noprotocol.com> | 2015-06-11 11:17:55 +0200 |
---|---|---|
committer | Anne Jan Brouwer <annejan@noprotocol.com> | 2015-06-11 11:17:55 +0200 |
commit | c141ca811dbed7756028220dc5740b3df9e9882b (patch) | |
tree | 468cf8abbdeabba561d104b976a96541576c07b9 | |
parent | cb5b828f169301a4b2663740323d78ff35e42f7c (diff) |
right click actions
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | mainwindow.cpp | 77 | ||||
-rw-r--r-- | mainwindow.h | 5 |
3 files changed, 80 insertions, 4 deletions
@@ -54,7 +54,7 @@ Planned features ---------------- * Re-encryption after users-change (optional ofcourse) * ~~Showing path in Add and Edit screen (currently sometimes confusing where I'm adding this password)~~ -* Right click handlers for file/folder and content +* ~~Right click handlers for file/folder and content~~ * ~~First use wizards to set up password-store (and decryption key, currently always the gpg default key)~~ * ~~Profiles (to allow use of multiple password stores and decryption keys) with dropdown in main screen~~ * Password generation with options for what kind you'd like diff --git a/mainwindow.cpp b/mainwindow.cpp index e625808f..500158e4 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -219,6 +219,9 @@ bool MainWindow::checkConfig() { ui->treeView->setHeaderHidden(true); ui->treeView->setIndentation(15); ui->treeView->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); + ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->treeView, SIGNAL(customContextMenuRequested(const QPoint&)), + this, SLOT(showContextMenu(const QPoint&))); ui->textBrowser->setOpenExternalLinks(true); @@ -815,7 +818,7 @@ void MainWindow::on_addButton_clicked() bool ok; QString dir = getDir(ui->treeView->currentIndex(), usePass); QString file = QInputDialog::getText(this, tr("New file"), - tr("New password file, will be placed in folder %1:").arg(QDir::separator() + dir), QLineEdit::Normal, + tr("New password file, will be placed in folder %1:").arg(QDir::separator() + getDir(ui->treeView->currentIndex(), true)), QLineEdit::Normal, "", &ok); if (!ok || file.isEmpty()) { return; @@ -835,7 +838,7 @@ 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(file), + tr("Are you sure you want to delete %1?").arg(QDir::separator() + file), QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) { return; } @@ -1195,3 +1198,73 @@ void MainWindow::closeEvent(QCloseEvent *event) } } +/** + * @brief MainWindow::showContextMenu + * @param pos + */ +void MainWindow::showContextMenu(const QPoint& pos) +{ + QPoint globalPos = ui->treeView->viewport()->mapToGlobal(pos); + + QFileInfo fileOrFolder = model.fileInfo(proxyModel.mapToSource(ui->treeView->currentIndex())); + + QMenu contextMenu; + if (fileOrFolder.isDir()) { + QAction* addFolder = contextMenu.addAction(tr("Add folder")); + QAction* addPassword = contextMenu.addAction(tr("Add password")); + QAction* users = contextMenu.addAction(tr("Users")); + connect(addFolder, SIGNAL(triggered()), this, SLOT(addFolder())); + connect(addPassword, SIGNAL(triggered()), this, SLOT(on_addButton_clicked())); + connect(users, SIGNAL(triggered()), this, SLOT(on_usersButton_clicked())); + } else if (fileOrFolder.isFile()) { + QAction* edit = contextMenu.addAction(tr("Edit")); + connect(edit, SIGNAL(triggered()), this, SLOT(editPassword())); + } + QAction* deleteItem = contextMenu.addAction(tr("Delete")); + connect(deleteItem, SIGNAL(triggered()), this, SLOT(on_deleteButton_clicked())); + + contextMenu.exec(globalPos); + } + +/** + * @brief MainWindow::addFolder + */ +void MainWindow::addFolder() +{ + bool ok; + QString dir = getDir(ui->treeView->currentIndex(), false); + QString newdir = QInputDialog::getText(this, tr("New file"), + tr("New folder, will be placed in folder %1:").arg(QDir::separator() + getDir(ui->treeView->currentIndex(), true)), QLineEdit::Normal, + "", &ok); + if (!ok || newdir.isEmpty()) { + return; + } + newdir.prepend(dir); + //qDebug() << newdir; + QDir().mkdir(newdir); + // TODO add to git? +} + +/** + * @brief MainWindow::editPassword + */ +void MainWindow::editPassword() +{ + // TODO move to editbutton stuff possibly? + currentDir = getDir(ui->treeView->currentIndex(), false); + lastDecrypt = "Could not decrypt"; + QString file = getFile(ui->treeView->currentIndex(), usePass); + if (!file.isEmpty()){ + currentAction = GPG; + if (usePass) { + executePass('"' + file + '"'); + } else { + executeWrapper(gpgExecutable , "-d --quiet --yes --no-encrypt-to --batch --use-agent \"" + file + '"'); + } + process->waitForFinished(30000); // long wait (passphrase stuff) + if (process->exitStatus() == QProcess::NormalExit) { + on_editButton_clicked(); + } + } +} + diff --git a/mainwindow.h b/mainwindow.h index e8960ef9..886a9482 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -68,6 +68,9 @@ private slots: void on_usersButton_clicked(); void messageAvailable(QString message); void on_profileBox_currentIndexChanged(QString); + void showContextMenu(const QPoint& pos); + void addFolder(); + void editPassword(); private: QApplication *QtPass; @@ -101,7 +104,7 @@ private: QStringList env; QQueue<execQueueItem> *execQueue; bool firstRun; - QDialog *keygen = 0; + QDialog *keygen = NULL; QString currentDir; QHash<QString, QString> profiles; QString profile; |