Page MenuHome GnuPG

No OneTemporary

diff --git a/mainwindow.cpp b/mainwindow.cpp
index 8882aca..6143402 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -1,390 +1,389 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QClipboard>
#include <QTimer>
/**
* @brief MainWindow::MainWindow
* @param parent
*/
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
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)));
ui->setupUi(this);
}
/**
* @brief MainWindow::~MainWindow
*/
MainWindow::~MainWindow()
{
delete ui;
}
/**
* @brief MainWindow::checkConfig
*/
void MainWindow::checkConfig() {
QSettings settings("IJHack", "QtPass");
usePass = (settings.value("usePass") == "true");
useClipboard = (settings.value("useClipboard") == "true");
useAutoclear = (settings.value("useAutoclear") == "true");
autoclearSeconds = settings.value("autoclearSeconds").toInt();
passStore = settings.value("passStore").toString();
if (passStore == "") {
passStore = QDir::homePath()+"/.password-store/";
/** @TODO exists? */
settings.setValue("passStore", passStore);
}
passExecutable = settings.value("passExecutable").toString();
if (passExecutable == "") {
process->start("which pass");
process->waitForFinished();
if (process->exitCode() == 0) {
passExecutable = process->readAllStandardOutput().trimmed();
settings.setValue("passExecutable", passExecutable);
usePass = true;
settings.setValue("usePass", "true");
}
}
gitExecutable = settings.value("gitExecutable").toString();
if (gitExecutable == "") {
process->start("which git");
process->waitForFinished();
if (process->exitCode() == 0) {
gitExecutable = process->readAllStandardOutput().trimmed();
settings.setValue("gitExecutable", gitExecutable);
}
}
gpgExecutable = settings.value("gpgExecutable").toString();
if (gpgExecutable == "") {
process->start("which gpg2");
process->waitForFinished();
if (process->exitCode() != 0) {
process->start("which gpg");
process->waitForFinished();
}
if (process->exitCode() == 0) {
gpgExecutable = process->readAllStandardOutput().trimmed();
settings.setValue("gpgExecutable", gpgExecutable);
}
}
if (passExecutable == "" && (gitExecutable == "" || gpgExecutable == "")) {
config();
}
model.setNameFilters(QStringList() << "*.gpg");
model.setNameFilterDisables(false);
proxyModel.setSourceModel(&model);
proxyModel.setModelAndStore(&model, passStore);
selectionModel = 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);
}
/**
* @brief MainWindow::config
*/
void MainWindow::config() {
d = 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);
if (d->exec()) {
if (d->result() == QDialog::Accepted) {
passExecutable = d->getPassPath();
gitExecutable = d->getGitPath();
gpgExecutable = d->getGpgPath();
passStore = d->getStorePath();
usePass = d->usePass();
useClipboard = d->useClipboard();
useAutoclear = d->useAutoclear();
autoclearSeconds = d->getAutoclear();
QSettings settings("IJHack", "QtPass");
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);
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");
}
}
/**
* @brief MainWindow::on_treeView_clicked
* @param index
*/
void MainWindow::on_treeView_clicked(const QModelIndex &index)
{
currentAction = GPG;
QString filePath = model.filePath(proxyModel.mapToSource(index));
QString passFile = filePath;
- passFile.replace(".gpg", "");
- passFile.replace(passStore, "");
-// ui->lineEdit->setText(passFile);
+ passFile.replace(QRegExp("\\.gpg$"), "");
+ passFile.replace(QRegExp("^" + passStore), "");
if (model.fileInfo(proxyModel.mapToSource(index)).isFile()){
if (usePass) {
executePass(passFile);
} else {
executeWrapper(gpgExecutable , "--no-tty -dq " + filePath);
}
}
}
/**
* @brief MainWindow::executePass
* @param args
*/
void MainWindow::executePass(QString args) {
executeWrapper(passExecutable, args);
}
/**
* @brief MainWindow::executeWrapper
* @param app
* @param args
*/
void MainWindow::executeWrapper(QString app, QString args) {
process->setWorkingDirectory(passStore);
process->start("sh", QStringList() << "-c" << app + " " + args);
ui->textBrowser->clear();
ui->textBrowser->setTextColor(Qt::black);
enableUiElements(false);
}
/**
* @brief MainWindow::readyRead
*/
void MainWindow::readyRead() {
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();
}
ui->textBrowser->setText(output);
}
/**
* @brief MainWindow::clearClipboard
* @TODO check clipboard content (only clear if contains the password)
*/
void MainWindow::clearClipboard()
{
QClipboard *clipboard = QApplication::clipboard();
clipboard->clear();
ui->statusBar->showMessage(tr("Clipboard cleared"), 3000);
}
/**
* @brief MainWindow::processFinished
* @param exitCode
* @param exitStatus
*/
void MainWindow::processFinished(int exitCode, QProcess::ExitStatus exitStatus) {
if (exitStatus != QProcess::NormalExit || exitCode > 0) {
ui->textBrowser->setTextColor(Qt::red);
}
readyRead();
enableUiElements(true);
if (currentAction == GPG && useClipboard) {
//Copy first line to clipboard
QClipboard *clip = QApplication::clipboard();
QStringList tokens = ui->textBrowser->document()->toPlainText().split("\n",QString::SkipEmptyParts);
clip->setText(tokens[0]);
ui->statusBar->showMessage(tr("Password copied to clipboard"), 3000);
if (useAutoclear) {
QTimer::singleShot(1000*autoclearSeconds, this, SLOT(clearClipboard()));
}
}
}
/**
* @brief MainWindow::enableUiElements
* @param state
*/
void MainWindow::enableUiElements(bool state) {
ui->updateButton->setEnabled(state);
ui->treeView->setEnabled(state);
ui->lineEdit->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);
}
/**
* @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();
}
diff --git a/resources.qrc b/resources.qrc
index b9b3a90..5171bf6 100644
--- a/resources.qrc
+++ b/resources.qrc
@@ -1,22 +1,18 @@
<RCC>
<qresource prefix="/">
<file>localization/localization_de_DE.qm</file>
<file>localization/localization_de_DE.ts</file>
<file>localization/localization_hu_HU.qm</file>
<file>localization/localization_hu_HU.ts</file>
<file>localization/localization_nl_NL.qm</file>
<file>localization/localization_nl_NL.ts</file>
<file>localization/localization_sv_SE.qm</file>
<file>localization/localization_sv_SE.ts</file>
<file>localization/localization_pl_PL.qm</file>
<file>localization/localization_pl_PL.ts</file>
<file>artwork/icon.icns</file>
<file>artwork/icon.ico</file>
<file>artwork/icon.png</file>
<file>artwork/icon.svg</file>
- <file>localization/localization_pl_PL.qm</file>
- <file>localization/localization_pl_PL.ts</file>
- <file>localization/localization_sv_SE.qm</file>
- <file>localization/localization_sv_SE.ts</file>
</qresource>
</RCC>
diff --git a/storemodel.cpp b/storemodel.cpp
index 7e889d3..213ba8c 100644
--- a/storemodel.cpp
+++ b/storemodel.cpp
@@ -1,68 +1,96 @@
#include "storemodel.h"
/**
* @brief StoreModel::StoreModel
* SubClass of QSortFilterProxyModel via http://www.qtcentre.org/threads/46471-QTreeView-Filter
*/
StoreModel::StoreModel()
{
}
/**
* @brief StoreModel::filterAcceptsRow
* @param sourceRow
* @param sourceParent
* @return
*/
bool StoreModel::filterAcceptsRow(int sourceRow,
const QModelIndex &sourceParent) const
{
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
return ShowThis(index);
}
/**
* @brief StoreModel::ShowThis
* @param index
* @return
*/
bool StoreModel::ShowThis(const QModelIndex index) const
{
bool retVal = false;
//Gives you the info for number of childs with a parent
if ( sourceModel()->rowCount(index) > 0 )
{
for( int nChild = 0; nChild < sourceModel()->rowCount(index); nChild++)
{
QModelIndex childIndex = sourceModel()->index(nChild,0,index);
if ( ! childIndex.isValid() )
break;
retVal = ShowThis(childIndex);
if (retVal)
{
break;
}
}
}
else
{
QModelIndex useIndex = sourceModel()->index(index.row(), 0, index.parent());
QString path = fs->filePath(useIndex);
- path.replace(".gpg", "");
- path.replace(store, "");
+ path.replace(QRegExp("\\.gpg$"), "");
+ path.replace(QRegExp("^" + store), "");
if ( ! path.contains(filterRegExp()))
{
retVal = false;
}
else
{
retVal = true;
}
}
return retVal;
}
+/**
+ * @brief StoreModel::setModelAndStore
+ * @param sourceModel
+ * @param passStore
+ */
void StoreModel::setModelAndStore(QFileSystemModel *sourceModel, QString passStore) {
fs = sourceModel;
store = passStore;
}
+
+/**
+ * @brief StoreModel::data
+ * @param index
+ * @param role
+ * @return
+ */
+QVariant StoreModel::data(const QModelIndex &index, int role) const
+{
+ if (!index.isValid())
+ return QVariant();
+
+ QVariant initial_value;
+ initial_value = QSortFilterProxyModel::data(index, role);
+
+ if (role == Qt::DisplayRole) {
+ QString name = initial_value.toString();
+ name.replace(QRegExp("\\.gpg$"), "");
+ initial_value.setValue(name);
+ }
+
+ return initial_value;
+}
diff --git a/storemodel.h b/storemodel.h
index cad3c8d..0f7488e 100644
--- a/storemodel.h
+++ b/storemodel.h
@@ -1,22 +1,24 @@
#ifndef STOREMODEL_H
#define STOREMODEL_H
#include <QSortFilterProxyModel>
#include <QFileSystemModel>
+#include <QRegExp>
class StoreModel : public QSortFilterProxyModel
{
Q_OBJECT
private:
QFileSystemModel* fs;
QString store;
public:
StoreModel();
bool filterAcceptsRow(int, const QModelIndex &) const;
bool ShowThis(const QModelIndex) const;
void setModelAndStore(QFileSystemModel *sourceModel, QString passStore);
+ QVariant data(const QModelIndex &index, int role) const;
};
#endif // STOREMODEL_H

File Metadata

Mime Type
text/x-diff
Expires
Sat, May 31, 8:00 AM (9 h, 21 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
a1/44/0d4a1f0dfb97c9f1c3af8a47b5e4

Event Timeline