Page Menu
Home
GnuPG
Search
Configure Global Search
Log In
Files
F25703810
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Size
33 KB
Subscribers
None
View Options
diff --git a/dialog.cpp b/dialog.cpp
index 09a2add..7e8d8fb 100644
--- a/dialog.cpp
+++ b/dialog.cpp
@@ -1,333 +1,332 @@
#include "dialog.h"
#include "ui_dialog.h"
/**
* @brief Dialog::Dialog
* @param parent
*/
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
}
/**
* @brief Dialog::~Dialog
*/
Dialog::~Dialog()
{
- delete ui;
}
/**
* @brief Dialog::setPassPath
* @param path
*/
void Dialog::setPassPath(QString path) {
ui->passPath->setText(path);
}
/**
* @brief Dialog::setGitPath
* @param path
*/
void Dialog::setGitPath(QString path) {
ui->gitPath->setText(path);
}
/**
* @brief Dialog::setGpgPath
* @param path
*/
void Dialog::setGpgPath(QString path) {
ui->gpgPath->setText(path);
}
/**
* @brief Dialog::setStorePath
* @param path
*/
void Dialog::setStorePath(QString path) {
ui->storePath->setText(path);
}
/**
* @brief Dialog::getPassPath
* @return
*/
QString Dialog::getPassPath() {
return ui->passPath->text();
}
/**
* @brief Dialog::getGitPath
* @return
*/
QString Dialog::getGitPath() {
return ui->gitPath->text();
}
/**
* @brief Dialog::getGpgPath
* @return
*/
QString Dialog::getGpgPath() {
return ui->gpgPath->text();
}
/**
* @brief Dialog::getStorePath
* @return
*/
QString Dialog::getStorePath() {
return ui->storePath->text();
}
/**
* @brief Dialog::usePass
* @return
*/
bool Dialog::usePass() {
return ui->radioButtonPass->isChecked();
}
/**
* @brief Dialog::usePass
* @param pass
*/
void Dialog::usePass(bool usePass) {
if (usePass) {
ui->radioButtonNative->setChecked(false);
ui->radioButtonPass->setChecked(true);
} else {
ui->radioButtonNative->setChecked(true);
ui->radioButtonPass->setChecked(false);
}
setGroupBoxState();
}
/**
* @brief Dialog::on_radioButtonNative_clicked
*/
void Dialog::on_radioButtonNative_clicked()
{
setGroupBoxState();
}
/**
* @brief Dialog::on_radioButtonPass_clicked
*/
void Dialog::on_radioButtonPass_clicked()
{
setGroupBoxState();
}
/**
* @brief Dialog::setGroupBoxState
*/
void Dialog::setGroupBoxState() {
if (ui->radioButtonPass->isChecked()) {
ui->groupBoxNative->setEnabled(false);
ui->groupBoxPass->setEnabled(true);
} else {
ui->groupBoxNative->setEnabled(true);
ui->groupBoxPass->setEnabled(false);
}
}
/**
* @brief Dialog::selectExecutable
* @return
*/
QString Dialog::selectExecutable() {
QFileDialog dialog(this);
dialog.setFileMode(QFileDialog::ExistingFile);
dialog.setOption(QFileDialog::ReadOnly);
if (dialog.exec()) {
return dialog.selectedFiles().first();
}
else return "";
}
/**
* @brief Dialog::selectFolder
* @return
*/
QString Dialog::selectFolder() {
QFileDialog dialog(this);
dialog.setFileMode(QFileDialog::Directory);
dialog.setOption(QFileDialog::ShowDirsOnly);
if (dialog.exec()) {
return dialog.selectedFiles().first();
}
else return "";
}
/**
* @brief Dialog::on_toolButtonGit_clicked
*/
void Dialog::on_toolButtonGit_clicked()
{
QString git = selectExecutable();
if (git != "") {
ui->gitPath->setText(git);
}
}
/**
* @brief Dialog::on_toolButtonGpg_clicked
*/
void Dialog::on_toolButtonGpg_clicked()
{
QString gpg = selectExecutable();
if (gpg != "") {
ui->gpgPath->setText(gpg);
}
}
/**
* @brief Dialog::on_toolButtonPass_clicked
*/
void Dialog::on_toolButtonPass_clicked()
{
QString pass = selectExecutable();
if (pass != "") {
ui->passPath->setText(pass);
}
}
/**
* @brief Dialog::on_toolButtonStore_clicked
*/
void Dialog::on_toolButtonStore_clicked()
{
QString store = selectFolder();
if (store != "") {
ui->storePath->setText(store);
}
}
/**
* @brief Dialog::on_checkBoxClipboard_clicked
*/
void Dialog::on_checkBoxClipboard_clicked()
{
if (ui->checkBoxClipboard->isChecked()) {
ui->checkBoxAutoclear->setEnabled(true);
ui->checkBoxHidePassword->setEnabled(true);
ui->checkBoxHideContent->setEnabled(true);
if (ui->checkBoxAutoclear->isChecked()) {
ui->spinBoxAutoclearSeconds->setEnabled(true);
ui->labelSeconds->setEnabled(true);
} else {
ui->spinBoxAutoclearSeconds->setEnabled(false);
ui->labelSeconds->setEnabled(false);
}
} else {
ui->checkBoxAutoclear->setEnabled(false);
ui->spinBoxAutoclearSeconds->setEnabled(false);
ui->labelSeconds->setEnabled(false);
ui->checkBoxHidePassword->setEnabled(false);
ui->checkBoxHideContent->setEnabled(false);
}
}
/**
* @brief Dialog::useClipboard
*/
void Dialog::useClipboard(bool useClipboard)
{
ui->checkBoxClipboard->setChecked(useClipboard);
on_checkBoxClipboard_clicked();
}
/**
* @brief Dialog::useAutoclear
* @param useAutoclear
*/
void Dialog::useAutoclear(bool useAutoclear)
{
ui->checkBoxAutoclear->setChecked(useAutoclear);
on_checkBoxAutoclear_clicked();
}
/**
* @brief Dialog::setAutoclear
* @param seconds
*/
void Dialog::setAutoclear(int seconds)
{
ui->spinBoxAutoclearSeconds->setValue(seconds);
}
/**
* @brief Dialog::useClipboard
* @return
*/
bool Dialog::useClipboard()
{
return ui->checkBoxClipboard->isChecked();
}
/**
* @brief Dialog::useAutoclear
* @return
*/
bool Dialog::useAutoclear()
{
return ui->checkBoxAutoclear->isChecked();
}
/**
* @brief Dialog::getAutoclear
* @return
*/
int Dialog::getAutoclear()
{
return ui->spinBoxAutoclearSeconds->value();
}
/**
* @brief Dialog::on_checkBoxAutoclear_clicked
*/
void Dialog::on_checkBoxAutoclear_clicked()
{
on_checkBoxClipboard_clicked();
}
/**
* @brief Dialog::hidePassword
* @return
*/
bool Dialog::hidePassword()
{
return ui->checkBoxHidePassword->isChecked();
}
/**
* @brief Dialog::hideContent
* @return
*/
bool Dialog::hideContent()
{
return ui->checkBoxHideContent->isChecked();
}
/**
* @brief Dialog::hidePassword
* @param hidePassword
*/
void Dialog::hidePassword(bool hidePassword)
{
ui->checkBoxHidePassword->setChecked(hidePassword);
}
/**
* @brief Dialog::hideContent
* @param hideContent
*/
void Dialog::hideContent(bool hideContent)
{
ui->checkBoxHideContent->setChecked(hideContent);
}
diff --git a/dialog.h b/dialog.h
index 01307a1..2220d68 100644
--- a/dialog.h
+++ b/dialog.h
@@ -1,58 +1,58 @@
#ifndef DIALOG_H
#define DIALOG_H
#include <QDialog>
#include <QFileDialog>
namespace Ui {
class Dialog;
}
class Dialog : public QDialog
{
Q_OBJECT
public:
explicit Dialog(QWidget *parent = 0);
~Dialog();
void setPassPath(QString);
void setGitPath(QString);
void setGpgPath(QString);
void setStorePath(QString);
void usePass(bool);
void useClipboard(bool);
void useAutoclear(bool);
void setAutoclear(int);
void hidePassword(bool);
void hideContent(bool);
QString getPassPath();
QString getGitPath();
QString getGpgPath();
QString getStorePath();
bool usePass();
bool useClipboard();
bool useAutoclear();
int getAutoclear();
bool hidePassword();
bool hideContent();
private slots:
void on_radioButtonNative_clicked();
void on_radioButtonPass_clicked();
void on_toolButtonGit_clicked();
void on_toolButtonGpg_clicked();
void on_toolButtonPass_clicked();
void on_toolButtonStore_clicked();
void on_checkBoxClipboard_clicked();
void on_checkBoxAutoclear_clicked();
private:
- Ui::Dialog *ui;
+ QScopedPointer<Ui::Dialog> ui;
void setGroupBoxState();
QString selectExecutable();
QString selectFolder();
};
#endif // DIALOG_H
diff --git a/mainwindow.cpp b/mainwindow.cpp
index bcbf35c..db6f598 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -1,563 +1,560 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "util.h"
#include <QClipboard>
#include <QInputDialog>
#include <QMessageBox>
#include <QTimer>
/**
* @brief MainWindow::MainWindow
* @param parent
*/
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
- settings(NULL),
- ui(new Ui::MainWindow)
+ ui(new Ui::MainWindow),
+ process(new QProcess(this))
{
- process = new QProcess(this);
-// connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(readyRead()));
- connect(process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(processError(QProcess::ProcessError)));
- connect(process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(processFinished(int, QProcess::ExitStatus)));
+// connect(process.data(), SIGNAL(readyReadStandardOutput()), this, SLOT(readyRead()));
+ connect(process.data(), SIGNAL(error(QProcess::ProcessError)), this, SLOT(processError(QProcess::ProcessError)));
+ connect(process.data(), SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(processFinished(int, QProcess::ExitStatus)));
ui->setupUi(this);
enableUiElements(true);
}
/**
* @brief MainWindow::~MainWindow
*/
MainWindow::~MainWindow()
{
- delete settings;
- delete ui;
}
void MainWindow::normalizePassStore() {
if (!passStore.endsWith("/") && !passStore.endsWith(QDir::separator())) {
passStore += '/';
}
}
QSettings &MainWindow::getSettings() {
if (!settings) {
QString portable_ini = QCoreApplication::applicationDirPath() + "/qtpass.ini";
if (QFile(portable_ini).exists()) {
- settings = new QSettings(portable_ini, QSettings::IniFormat);
+ settings.reset(new QSettings(portable_ini, QSettings::IniFormat));
} else {
- settings = new QSettings("IJHack", "QtPass");
+ settings.reset(new QSettings("IJHack", "QtPass"));
}
}
return *settings;
}
/**
* @brief MainWindow::checkConfig
*/
void MainWindow::checkConfig() {
QSettings &settings(getSettings());
usePass = (settings.value("usePass") == "true");
useClipboard = (settings.value("useClipboard") == "true");
useAutoclear = (settings.value("useAutoclear") == "true");
autoclearSeconds = settings.value("autoclearSeconds").toInt();
hidePassword = (settings.value("hidePassword") == "true");
hideContent = (settings.value("hideContent") == "true");
passStore = settings.value("passStore").toString();
if (passStore == "") {
passStore = Util::findPasswordStore();
settings.setValue("passStore", passStore);
}
normalizePassStore();
passExecutable = settings.value("passExecutable").toString();
if (passExecutable == "") {
passExecutable = Util::findBinaryInPath("pass");
}
gitExecutable = settings.value("gitExecutable").toString();
if (gitExecutable == "") {
gitExecutable = Util::findBinaryInPath("git");
}
gpgExecutable = settings.value("gpgExecutable").toString();
if (gpgExecutable == "") {
gpgExecutable = Util::findBinaryInPath("gpg");
}
gpgHome = settings.value("gpgHome").toString();
if (passExecutable == "" && (gitExecutable == "" || gpgExecutable == "")) {
config();
}
model.setNameFilters(QStringList() << "*.gpg");
model.setNameFilterDisables(false);
proxyModel.setSourceModel(&model);
proxyModel.setModelAndStore(&model, passStore);
- selectionModel = new QItemSelectionModel(&proxyModel);
+ selectionModel.reset(new QItemSelectionModel(&proxyModel));
model.fetchMore(model.setRootPath(passStore));
model.sort(0, Qt::AscendingOrder);
ui->treeView->setModel(&proxyModel);
ui->treeView->setRootIndex(proxyModel.mapFromSource(model.setRootPath(passStore)));
ui->treeView->setColumnHidden(1, true);
ui->treeView->setColumnHidden(2, true);
ui->treeView->setColumnHidden(3, true);
ui->treeView->setHeaderHidden(true);
ui->treeView->setIndentation(15);
ui->treeView->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
ui->textBrowser->setOpenExternalLinks(true);
ui->lineEdit->setFocus();
}
/**
* @brief MainWindow::config
*/
void MainWindow::config() {
- d = new Dialog();
+ d.reset(new Dialog());
d->setModal(true);
d->setPassPath(passExecutable);
d->setGitPath(gitExecutable);
d->setGpgPath(gpgExecutable);
d->setStorePath(passStore);
d->usePass(usePass);
d->useClipboard(useClipboard);
d->useAutoclear(useAutoclear);
d->setAutoclear(autoclearSeconds);
d->hidePassword(hidePassword);
d->hideContent(hideContent);
if (d->exec()) {
if (d->result() == QDialog::Accepted) {
passExecutable = d->getPassPath();
gitExecutable = d->getGitPath();
gpgExecutable = d->getGpgPath();
passStore = d->getStorePath();
normalizePassStore();
usePass = d->usePass();
useClipboard = d->useClipboard();
useAutoclear = d->useAutoclear();
autoclearSeconds = d->getAutoclear();
hidePassword = d->hidePassword();
hideContent = d->hideContent();
QSettings &settings(getSettings());
settings.setValue("passExecutable", passExecutable);
settings.setValue("gitExecutable", gitExecutable);
settings.setValue("gpgExecutable", gpgExecutable);
settings.setValue("passStore", passStore);
settings.setValue("usePass", usePass ? "true" : "false");
settings.setValue("useClipboard", useClipboard ? "true" : "false");
settings.setValue("useAutoclear", useAutoclear ? "true" : "false");
settings.setValue("autoclearSeconds", autoclearSeconds);
settings.setValue("hidePassword", hidePassword ? "true" : "false");
settings.setValue("hideContent", hideContent ? "true" : "false");
ui->treeView->setRootIndex(model.setRootPath(passStore));
}
}
}
/**
* @brief MainWindow::on_updateButton_clicked
*/
void MainWindow::on_updateButton_clicked()
{
ui->statusBar->showMessage(tr("Updating password-store"), 2000);
currentAction = GIT;
if (usePass) {
executePass("git pull");
} else {
executeWrapper(gitExecutable, "pull");
}
}
QString MainWindow::getFile(const QModelIndex &index, bool forPass)
{
if (!index.isValid() || !model.fileInfo(proxyModel.mapToSource(index)).isFile()) {
return QString();
}
QString filePath = model.filePath(proxyModel.mapToSource(index));
if (forPass) {
filePath.replace(QRegExp("\\.gpg$"), "");
filePath.replace(QRegExp("^" + passStore), "");
}
return filePath;
}
/**
* @brief MainWindow::on_treeView_clicked
* @param index
*/
void MainWindow::on_treeView_clicked(const QModelIndex &index)
{
lastDecrypt = "Could not decrypt";
QString file = getFile(index, usePass);
if (!file.isEmpty()){
currentAction = GPG;
if (usePass) {
executePass('"' + file + '"');
} else {
executeWrapper(gpgExecutable , "--no-tty --use-agent -dq \"" + file + '"');
}
}
}
/**
* @brief MainWindow::executePass
* @param args
*/
void MainWindow::executePass(QString args, QString input) {
executeWrapper(passExecutable, args, input);
}
/**
* @brief MainWindow::executeWrapper
* @param app
* @param args
*/
void MainWindow::executeWrapper(QString app, QString args, QString input) {
process->setWorkingDirectory(passStore);
if (!gpgHome.isEmpty()) {
QStringList env = QProcess::systemEnvironment();
QDir absHome(gpgHome);
absHome.makeAbsolute();
env << "GNUPGHOME=" + absHome.path();
process->setEnvironment(env);
}
process->start('"' + app + "\" " + args);
ui->textBrowser->clear();
ui->textBrowser->setTextColor(Qt::black);
enableUiElements(false);
if (!input.isEmpty()) {
process->write(input.toUtf8());
}
process->closeWriteChannel();
}
/**
* @brief MainWindow::readyRead
*/
void MainWindow::readyRead(bool finished = false) {
QString output = ui->textBrowser->document()->toPlainText();
QString error = process->readAllStandardError();
if (error.size() > 0) {
ui->textBrowser->setTextColor(Qt::red);
output += error;
} else {
output += process->readAllStandardOutput();
if (finished && currentAction == GPG) {
lastDecrypt = output;
if (useClipboard) {
QClipboard *clip = QApplication::clipboard();
QStringList tokens = output.split("\n");
clip->setText(tokens[0]);
ui->statusBar->showMessage(tr("Password copied to clipboard"), 3000);
if (useAutoclear) {
clippedPass = tokens[0];
QTimer::singleShot(1000*autoclearSeconds, this, SLOT(clearClipboard()));
}
if (hidePassword) {
tokens.pop_front();
output = tokens.join("\n");
}
if (hideContent) {
output = tr("Content hidden");
}
}
}
}
output.replace(QRegExp("<"), "<");
output.replace(QRegExp(">"), ">");
output.replace(QRegExp("((http|https|ftp)\\://[a-zA-Z0-9\\-\\.]+\\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\\-\\._\\?\\,\\'/\\\\+&%\\$#\\=~])*)"), "<a href=\"\\1\">\\1</a>");
output.replace(QRegExp("\n"), "<br />");
ui->textBrowser->setHtml(output);
}
/**
* @brief MainWindow::clearClipboard
* @TODO check clipboard content (only clear if contains the password)
*/
void MainWindow::clearClipboard()
{
QClipboard *clipboard = QApplication::clipboard();
if (clipboard->text() == clippedPass) {
clipboard->clear();
clippedPass = "";
ui->statusBar->showMessage(tr("Clipboard cleared"), 3000);
} else {
ui->statusBar->showMessage(tr("Clipboard not cleared"), 3000);
}
}
/**
* @brief MainWindow::processFinished
* @param exitCode
* @param exitStatus
*/
void MainWindow::processFinished(int exitCode, QProcess::ExitStatus exitStatus) {
bool error = exitStatus != QProcess::NormalExit || exitCode > 0;
if (error) {
ui->textBrowser->setTextColor(Qt::red);
}
readyRead(true);
enableUiElements(true);
if (!error && currentAction == EDIT) {
on_treeView_clicked(ui->treeView->currentIndex());
}
}
/**
* @brief MainWindow::enableUiElements
* @param state
*/
void MainWindow::enableUiElements(bool state) {
ui->updateButton->setEnabled(state);
ui->treeView->setEnabled(state);
ui->lineEdit->setEnabled(state);
ui->addButton->setEnabled(state);
state &= ui->treeView->currentIndex().isValid();
ui->deleteButton->setEnabled(state);
ui->editButton->setEnabled(state);
}
/**
* @brief MainWindow::processError
* @param error
*/
void MainWindow::processError(QProcess::ProcessError error)
{
QString errorString;
switch (error) {
case QProcess::FailedToStart:
errorString = tr("QProcess::FailedToStart");
break;
case QProcess::Crashed:
errorString = tr("QProcess::Crashed");
break;
case QProcess::Timedout:
errorString = tr("QProcess::Timedout");
break;
case QProcess::ReadError:
errorString = tr("QProcess::ReadError");
break;
case QProcess::WriteError:
errorString = tr("QProcess::WriteError");
break;
case QProcess::UnknownError:
errorString = tr("QProcess::UnknownError");
break;
}
ui->textBrowser->setTextColor(Qt::red);
ui->textBrowser->setText(errorString);
if (process->state() == QProcess::NotRunning)
enableUiElements(true);
}
/**
* @brief MainWindow::setPassExecutable
* @param path
*/
void MainWindow::setPassExecutable(QString path) {
passExecutable = path;
}
/**
* @brief MainWindow::setGitExecutable
* @param path
*/
void MainWindow::setGitExecutable(QString path) {
gitExecutable = path;
}
/**
* @brief MainWindow::setGpgExecutable
* @param path
*/
void MainWindow::setGpgExecutable(QString path) {
gpgExecutable = path;
}
/**
* @brief MainWindow::on_configButton_clicked
*/
void MainWindow::on_configButton_clicked()
{
config();
}
/**
* @brief MainWindow::on_lineEdit_textChanged
* @param arg1
*/
void MainWindow::on_lineEdit_textChanged(const QString &arg1)
{
ui->treeView->expandAll();
ui->statusBar->showMessage(tr("Looking for: ") + arg1, 1000);
QString query = arg1;
query.replace(QRegExp(" "), ".*");
QRegExp regExp(query, Qt::CaseInsensitive);
proxyModel.setFilterRegExp(regExp);
ui->treeView->setRootIndex(proxyModel.mapFromSource(model.setRootPath(passStore)));
selectFirstFile();
}
/**
* @brief MainWindow::on_lineEdit_returnPressed
*/
void MainWindow::on_lineEdit_returnPressed()
{
selectFirstFile();
on_treeView_clicked(ui->treeView->currentIndex());
}
/**
* @brief MainWindow::selectFirstFile
*/
void MainWindow::selectFirstFile()
{
QModelIndex index = proxyModel.mapFromSource(model.setRootPath(passStore));
index = firstFile(index);
ui->treeView->setCurrentIndex(index);
}
/**
* @brief MainWindow::firstFile
* @param parentIndex
* @return QModelIndex
*/
QModelIndex MainWindow::firstFile(QModelIndex parentIndex) {
QModelIndex index = parentIndex;
int numRows = proxyModel.rowCount(parentIndex);
for (int row = 0; row < numRows; ++row) {
index = proxyModel.index(row, 0, parentIndex);
if (model.fileInfo(proxyModel.mapToSource(index)).isFile()) {
return index;
}
if (proxyModel.hasChildren(index)) {
return firstFile(index);
}
}
return index;
}
/**
* @brief MainWindow::on_clearButton_clicked
*/
void MainWindow::on_clearButton_clicked()
{
ui->lineEdit->clear();
}
void MainWindow::setPassword(QString file, bool overwrite)
{
bool ok;
#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
QString newValue = QInputDialog::getMultiLineText(this, tr("New Value"),
tr("New password value:"),
lastDecrypt, &ok);
#else
QString newValue = QInputDialog::getText(this, tr("New Value"),
tr("New password value:"), QLineEdit::Normal,
lastDecrypt, &ok);
#endif
if (!ok || newValue.isEmpty()) {
return;
}
currentAction = EDIT;
if (usePass) {
QString force(overwrite ? " -f " : " ");
executePass("insert" + force + "-m \"" + file + '"', newValue);
} else {
QFile gpgId(passStore + ".gpg-id");
if (!gpgId.open(QIODevice::ReadOnly | QIODevice::Text)) {
QMessageBox::critical(this, tr("Can not edit"),
tr("Password store lacks .gpg-id specifying encryption key"));
return;
}
QString recipient(gpgId.readAll());
if (recipient.isEmpty()) {
QMessageBox::critical(this, tr("Can not edit"),
tr("Could not read encryption key to use"));
return;
}
file += ".gpg";
QString force(overwrite ? " --yes " : " ");
executeWrapper(gpgExecutable , force + "--batch -eq --output \"" + file + "\" -r " + recipient + " -", newValue);
}
}
void MainWindow::on_addButton_clicked()
{
bool ok;
QString file = QInputDialog::getText(this, tr("New file"),
tr("New password file:"), QLineEdit::Normal,
"", &ok);
if (!ok || file.isEmpty()) {
return;
}
lastDecrypt = "";
setPassword(file, false);
}
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),
QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) {
return;
}
currentAction = DELETE;
if (usePass) {
executePass("rm -f \"" + file + '"');
} else {
QFile(file).remove();
}
}
void MainWindow::on_editButton_clicked()
{
QString file = getFile(ui->treeView->currentIndex(), usePass);
if (file.isEmpty()) {
QMessageBox::critical(this, tr("Can not edit"),
tr("Selected password file does not exist, not able to edit"));
return;
}
setPassword(file, true);
}
/**
* @brief MainWindow::setApp
* @param app
*/
void MainWindow::setApp(SingleApplication *app)
{
a = app;
connect(a, SIGNAL(messageAvailable(QString)), this, SLOT(messageAvailable(QString)));
}
/**
* @brief MainWindow::messageAvailable
* @param message
*/
void MainWindow::messageAvailable(QString message)
{
if (message == "show") {
ui->lineEdit->selectAll();
ui->lineEdit->setFocus();
} else {
ui->treeView->expandAll();
ui->lineEdit->setText(message);
on_lineEdit_returnPressed();
}
show();
raise();
}
diff --git a/mainwindow.h b/mainwindow.h
index 55f320a..0de86aa 100644
--- a/mainwindow.h
+++ b/mainwindow.h
@@ -1,84 +1,84 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QTreeView>
#include <QFileSystemModel>
#include <QProcess>
#include <QSettings>
#include "storemodel.h"
#include "dialog.h"
#include "singleapplication.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
enum actionType { GPG, GIT, EDIT, DELETE };
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
void setPassExecutable(QString);
void setGitExecutable(QString);
void setGpgExecutable(QString);
void checkConfig();
void setApp(SingleApplication* app);
private slots:
void on_updateButton_clicked();
void on_treeView_clicked(const QModelIndex &index);
void on_configButton_clicked();
void readyRead(bool finished);
void processFinished(int, QProcess::ExitStatus);
void processError(QProcess::ProcessError);
void clearClipboard();
void on_lineEdit_textChanged(const QString &arg1);
void on_lineEdit_returnPressed();
void on_clearButton_clicked();
void on_addButton_clicked();
void on_deleteButton_clicked();
void on_editButton_clicked();
void messageAvailable(QString message);
private:
- QSettings *settings;
- Ui::MainWindow *ui;
+ QScopedPointer<QSettings> settings;
+ QScopedPointer<Ui::MainWindow> ui;
QFileSystemModel model;
StoreModel proxyModel;
- QItemSelectionModel *selectionModel;
- QProcess *process;
+ QScopedPointer<QItemSelectionModel> selectionModel;
+ QScopedPointer<QProcess> process;
SingleApplication *a;
- Dialog* d;
+ QScopedPointer<Dialog> d;
bool usePass;
bool useClipboard;
bool useAutoclear;
bool hidePassword;
bool hideContent;
int autoclearSeconds;
QString passStore;
QString passExecutable;
QString gitExecutable;
QString gpgExecutable;
QString gpgHome;
QString clippedPass;
actionType currentAction;
QString lastDecrypt;
void updateText();
void executePass(QString, QString = QString());
void executeWrapper(QString, QString, QString = QString());
void config();
void enableUiElements(bool);
void selectFirstFile();
QModelIndex firstFile(QModelIndex parentIndex);
QString getFile(const QModelIndex &, bool);
void setPassword(QString, bool);
void normalizePassStore();
QSettings &getSettings();
};
#endif // MAINWINDOW_H
diff --git a/singleapplication.cpp b/singleapplication.cpp
index 3c48436..8573a8c 100644
--- a/singleapplication.cpp
+++ b/singleapplication.cpp
@@ -1,85 +1,85 @@
#include <QLocalSocket>
#include "singleapplication.h"
/**
* @brief SingleApplication::SingleApplication
* @param argc
* @param argv
* @param uniqueKey
*/
SingleApplication::SingleApplication(int &argc, char *argv[], const QString uniqueKey) : QApplication(argc, argv), _uniqueKey(uniqueKey)
{
sharedMemory.setKey(_uniqueKey);
if (sharedMemory.attach())
_isRunning = true;
else
{
_isRunning = false;
// create shared memory.
if (!sharedMemory.create(1))
{
qDebug("Unable to create single instance.");
return;
}
// create local server and listen to incomming messages from other instances.
- localServer = new QLocalServer(this);
- connect(localServer, SIGNAL(newConnection()), this, SLOT(receiveMessage()));
+ localServer.reset(new QLocalServer(this));
+ connect(localServer.data(), SIGNAL(newConnection()), this, SLOT(receiveMessage()));
localServer->listen(_uniqueKey);
}
}
// public slots.
/**
* @brief SingleApplication::receiveMessage
*/
void SingleApplication::receiveMessage()
{
QLocalSocket *localSocket = localServer->nextPendingConnection();
if (!localSocket->waitForReadyRead(timeout))
{
qDebug() << localSocket->errorString().toLatin1();
return;
}
QByteArray byteArray = localSocket->readAll();
QString message = QString::fromUtf8(byteArray.constData());
emit messageAvailable(message);
localSocket->disconnectFromServer();
}
// public functions.
/**
* @brief SingleApplication::isRunning
* @return
*/
bool SingleApplication::isRunning()
{
return _isRunning;
}
/**
* @brief SingleApplication::sendMessage
* @param message
* @return
*/
bool SingleApplication::sendMessage(const QString &message)
{
if (!_isRunning)
return false;
QLocalSocket localSocket(this);
localSocket.connectToServer(_uniqueKey, QIODevice::WriteOnly);
if (!localSocket.waitForConnected(timeout))
{
qDebug() << localSocket.errorString().toLatin1();
return false;
}
localSocket.write(message.toUtf8());
if (!localSocket.waitForBytesWritten(timeout))
{
qDebug() << localSocket.errorString().toLatin1();
return false;
}
localSocket.disconnectFromServer();
return true;
}
diff --git a/singleapplication.h b/singleapplication.h
index 85c5f60..966dc95 100644
--- a/singleapplication.h
+++ b/singleapplication.h
@@ -1,31 +1,31 @@
#ifndef SINGLE_APPLICATION_H
#define SINGLE_APPLICATION_H
#include <QApplication>
#include <QSharedMemory>
#include <QLocalServer>
class SingleApplication : public QApplication
{
Q_OBJECT
public:
SingleApplication(int &argc, char *argv[], const QString uniqueKey);
bool isRunning();
bool sendMessage(const QString &message);
public slots:
void receiveMessage();
signals:
void messageAvailable(QString message);
private:
bool _isRunning;
QString _uniqueKey;
QSharedMemory sharedMemory;
- QLocalServer *localServer;
+ QScopedPointer<QLocalServer> localServer;
static const int timeout = 1000;
};
#endif // SINGLE_APPLICATION_H
diff --git a/util.cpp b/util.cpp
index ed352d6..3afd3be 100644
--- a/util.cpp
+++ b/util.cpp
@@ -1,67 +1,67 @@
#include <QDebug>
#include <QFileInfo>
#include <QProcessEnvironment>
#include <QString>
#include <QDir>
#include "util.h"
QProcessEnvironment Util::_env;
bool Util::_envInitialised;
void Util::initialiseEnvironment()
{
if (!_envInitialised) {
_env = QProcessEnvironment::systemEnvironment();
_envInitialised = true;
}
}
QString Util::findPasswordStore()
{
QString path;
initialiseEnvironment();
if (_env.contains("PASSWORD_STORE_DIR")) {
path = _env.value("PASSWORD_STORE_DIR");
} else {
/* @TODO checks */
path = QDir::homePath()+"/.password-store/";
}
return path;
}
QString Util::findBinaryInPath(QString binary)
{
initialiseEnvironment();
QString ret = "";
binary.prepend("/");
if (_env.contains("PATH")) {
QString path = _env.value("PATH");
QStringList entries = path.split(':');
if (entries.length() < 2) {
entries = path.split(';');
}
foreach(QString entry, entries) {
- QFileInfo *qfi = new QFileInfo(entry.append(binary));
+ QScopedPointer<QFileInfo> qfi(new QFileInfo(entry.append(binary)));
qDebug() << entry;
#ifdef WINDOWS
if (!qfi->exists()) {
QFileInfo qfi = new QFileInfo(entry.append(".exe"));
}
#endif
if (!qfi->isExecutable()) {
continue;
}
ret = qfi->absoluteFilePath();
break;
}
}
return ret;
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Tue, Jul 8, 12:37 PM (4 h, 45 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
38/af/8d78e881f09ba2d80326e4fe713a
Attached To
rGPGPASS GnuPG Password Manager
Event Timeline
Log In to Comment