diff options
author | Anne Jan Brouwer <brouwer@annejan.com> | 2015-06-11 11:17:55 +0200 |
---|---|---|
committer | Anne Jan Brouwer <annejan@noprotocol.com> | 2015-06-11 11:17:55 +0200 |
commit | 1985ad51abc875558ec651e069adbff99661c98d (patch) | |
tree | 468cf8abbdeabba561d104b976a96541576c07b9 /mainwindow.cpp | |
parent | 356015f8740cf4f87cfa5ae96bfa280f68b707e9 (diff) |
right click actions
Diffstat (limited to 'mainwindow.cpp')
-rw-r--r-- | mainwindow.cpp | 77 |
1 files changed, 75 insertions, 2 deletions
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(); + } + } +} + |