summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnne Jan Brouwer <brouwer@annejan.com>2015-06-11 17:32:38 +0200
committerAnne Jan Brouwer <brouwer@annejan.com>2015-06-11 17:32:38 +0200
commitcecb35dffd88c566e2b90609ce1fe81d28f67a6c (patch)
tree03d61f0a538e33e59a340c84588514038f9f1777
parenta3167fa986a4b733118853b984497e5a76161bda (diff)
parentb36b79153b73606261018bfbe1b7395c2ecf54fb (diff)
Merge pull request #52 from IJHack/develop
Right click actions and many many small fixes.
-rw-r--r--README.md4
-rw-r--r--dialog.cpp4
-rw-r--r--keygendialog.cpp6
-rw-r--r--main.cpp11
-rw-r--r--mainwindow.cpp160
-rw-r--r--mainwindow.h6
-rw-r--r--qtpass.pro2
-rw-r--r--storemodel.cpp17
-rw-r--r--usersdialog.cpp1
9 files changed, 174 insertions, 37 deletions
diff --git a/README.md b/README.md
index ee049c47..394cd2aa 100644
--- a/README.md
+++ b/README.md
@@ -53,8 +53,8 @@ Known issues
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
+* ~~Showing path in Add and Edit screen (currently sometimes confusing where I'm adding this password)~~
+* ~~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/dialog.cpp b/dialog.cpp
index 4b7de9a7..721840ed 100644
--- a/dialog.cpp
+++ b/dialog.cpp
@@ -510,7 +510,9 @@ void Dialog::wizard()
//qDebug() << names;
if (QFile(gpg).exists() && names.empty()) {
KeygenDialog d(this);
- d.exec();
+ if (!d.exec()) {
+ return;
+ }
}
QString passStore = ui->storePath->text();
diff --git a/keygendialog.cpp b/keygendialog.cpp
index 4c5b2c5a..0ae92c14 100644
--- a/keygendialog.cpp
+++ b/keygendialog.cpp
@@ -124,9 +124,9 @@ void KeygenDialog::done(int r)
ui->frame->hide();
ui->label->setText(QString("This operation can take some minutes.<br />") +
- "We need to generate a lot of random bytes. It is a good idea to perform " +
- "some other action (type on the keyboard, move the mouse, utilize the " +
- "disks) during the prime generation; this gives the random number " +
+ "We need to generate a lot of random bytes. It is a good idea to perform "
+ "some other action (type on the keyboard, move the mouse, utilize the "
+ "disks) during the prime generation; this gives the random number "
"generator a better chance to gain enough entropy.");
this->layout()->addWidget(pi);
diff --git a/main.cpp b/main.cpp
index 9def9777..8f397ab8 100644
--- a/main.cpp
+++ b/main.cpp
@@ -41,12 +41,7 @@ int main(int argc, char *argv[])
app.setActiveWindow(&w);
app.setWindowIcon(QIcon(":artwork/icon.png"));
w.setApp(&app);
- if (w.checkConfig()) {
- w.setText(text);
- w.show();
- return app.exec();
- } else {
- // canceled out of wizard
- return 0;
- }
+ w.setText(text);
+ w.show();
+ return app.exec();
}
diff --git a/mainwindow.cpp b/mainwindow.cpp
index c106c09a..9785be45 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -13,6 +13,8 @@
#include <QQueue>
#include <QCloseEvent>
#ifdef Q_OS_WIN
+#define WIN32_LEAN_AND_MEAN/*_KILLING_MACHINE*/
+#define WIN32_EXTRA_LEAN
#include <windows.h>
#include <winnetwk.h>
#undef DELETE
@@ -38,6 +40,11 @@ MainWindow::MainWindow(QWidget *parent) :
ui->statusBar->showMessage(tr("Welcome to QtPass %1").arg(VERSION), 2000);
firstRun = true;
startupPhase = true;
+ if (!checkConfig()) {
+ // no working config
+ QApplication::quit();
+ }
+ QtPass = NULL;
}
/**
@@ -214,6 +221,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);
@@ -256,6 +266,9 @@ void MainWindow::config() {
QScopedPointer<Dialog> d(new Dialog(this));
d->setModal(true);
+ // Automatically default to pass if it's available
+ usePass = firstRun ? QFile(passExecutable).exists() : usePass;
+
d->setPassPath(passExecutable);
d->setGitPath(gitExecutable);
d->setGpgPath(gpgExecutable);
@@ -421,6 +434,9 @@ void MainWindow::on_treeView_clicked(const QModelIndex &index)
} else {
executeWrapper(gpgExecutable , "-d --quiet --yes --no-encrypt-to --batch --use-agent \"" + file + '"');
}
+ } else {
+ ui->editButton->setEnabled(false);
+ ui->deleteButton->setEnabled(true);
}
}
@@ -808,13 +824,14 @@ void MainWindow::setPassword(QString file, bool overwrite)
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:"), 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;
}
- file = getDir(ui->treeView->currentIndex(), usePass) + file;
+ file = dir + file;
if (!usePass) {
file += ".gpg";
}
@@ -827,18 +844,67 @@ void MainWindow::on_addButton_clicked()
*/
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 + '"');
+ QFileInfo fileOrFolder = model.fileInfo(proxyModel.mapToSource(ui->treeView->currentIndex()));
+ QString file = "";
+
+ if (fileOrFolder.isFile()) {
+ file = getFile(ui->treeView->currentIndex(), usePass);
+ if (QMessageBox::question(this, tr("Delete password?"),
+ tr("Are you sure you want to delete %1?").arg(QDir::separator() + getFile(ui->treeView->currentIndex(), true)),
+ QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) {
+ return;
+ }
+ if (usePass) {
+ currentAction = DELETE;
+ executePass("rm -f \"" + file + '"');
+ } else {
+ // TODO GIT
+ QFile(file).remove();
+ }
} else {
- QFile(file).remove();
+ file = getDir(ui->treeView->currentIndex(), false);
+ if (QMessageBox::question(this, tr("Delete folder?"),
+ tr("Are you sure you want to delete %1?").arg(QDir::separator() + getDir(ui->treeView->currentIndex(), true)),
+ QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) {
+ return;
+ }
+ // TODO GIT
+#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
+ QDir dir(file);
+ dir.removeRecursively();
+#else
+ removeDir(file);
+#endif
}
+
+}
+
+/**
+ * @brief MainWindow::removeDir
+ * @param dirName
+ * @return
+ */
+bool MainWindow::removeDir(const QString & dirName)
+{
+ bool result = true;
+ QDir dir(dirName);
+
+ if (dir.exists(dirName)) {
+ Q_FOREACH(QFileInfo info, dir.entryInfoList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden | QDir::AllDirs | QDir::Files, QDir::DirsFirst)) {
+ if (info.isDir()) {
+ result = removeDir(info.absoluteFilePath());
+ }
+ else {
+ result = QFile::remove(info.absoluteFilePath());
+ }
+
+ if (!result) {
+ return result;
+ }
+ }
+ result = dir.rmdir(dirName);
+ }
+ return result;
}
/**
@@ -1189,3 +1255,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..163e626e 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;
@@ -128,6 +131,7 @@ private:
void updateProfileBox();
void initTrayIcon();
void destroyTrayIcon();
+ bool removeDir(const QString & dirName);
};
#endif // MAINWINDOW_H
diff --git a/qtpass.pro b/qtpass.pro
index e9f668aa..57e08b3f 100644
--- a/qtpass.pro
+++ b/qtpass.pro
@@ -20,7 +20,7 @@ macx {
}
TEMPLATE = app
-VERSION = 0.8.3
+VERSION = 0.8.4
SOURCES += main.cpp\
mainwindow.cpp \
diff --git a/storemodel.cpp b/storemodel.cpp
index 213ba8c3..3738236f 100644
--- a/storemodel.cpp
+++ b/storemodel.cpp
@@ -6,6 +6,7 @@
*/
StoreModel::StoreModel()
{
+ fs = NULL;
}
/**
@@ -29,14 +30,19 @@ bool StoreModel::filterAcceptsRow(int sourceRow,
bool StoreModel::ShowThis(const QModelIndex index) const
{
bool retVal = false;
+ if (fs == NULL) {
+ return retVal;
+ }
//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() )
+ if (!childIndex.isValid())
+ {
break;
+ }
retVal = ShowThis(childIndex);
if (retVal)
{
@@ -50,14 +56,7 @@ bool StoreModel::ShowThis(const QModelIndex index) const
QString path = fs->filePath(useIndex);
path.replace(QRegExp("\\.gpg$"), "");
path.replace(QRegExp("^" + store), "");
- if ( ! path.contains(filterRegExp()))
- {
- retVal = false;
- }
- else
- {
- retVal = true;
- }
+ retVal = path.contains(filterRegExp());
}
return retVal;
}
diff --git a/usersdialog.cpp b/usersdialog.cpp
index 189fd1b8..dd0b6517 100644
--- a/usersdialog.cpp
+++ b/usersdialog.cpp
@@ -10,6 +10,7 @@ UsersDialog::UsersDialog(QWidget *parent) :
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
connect(ui->listWidget, SIGNAL(itemChanged(QListWidgetItem *)), this, SLOT(itemChange(QListWidgetItem *)));
+ userList = NULL;
}
UsersDialog::~UsersDialog()