Skip to content

Commit

Permalink
Merge pull request #52 from IJHack/develop
Browse files Browse the repository at this point in the history
Right click actions and many many small fixes.
  • Loading branch information
annejan committed Jun 11, 2015
2 parents ae415d3 + 7db530d commit e58b9a9
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 37 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion dialog.cpp
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions keygendialog.cpp
Expand Up @@ -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);
Expand Down
11 changes: 3 additions & 8 deletions main.cpp
Expand Up @@ -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();
}
160 changes: 148 additions & 12 deletions mainwindow.cpp
Expand Up @@ -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
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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";
}
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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();
}
}
}

6 changes: 5 additions & 1 deletion mainwindow.h
Expand Up @@ -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;
Expand Down Expand Up @@ -101,7 +104,7 @@ private slots:
QStringList env;
QQueue<execQueueItem> *execQueue;
bool firstRun;
QDialog *keygen = 0;
QDialog *keygen = NULL;
QString currentDir;
QHash<QString, QString> profiles;
QString profile;
Expand All @@ -128,6 +131,7 @@ private slots:
void updateProfileBox();
void initTrayIcon();
void destroyTrayIcon();
bool removeDir(const QString & dirName);
};

#endif // MAINWINDOW_H
2 changes: 1 addition & 1 deletion qtpass.pro
Expand Up @@ -20,7 +20,7 @@ macx {
}

TEMPLATE = app
VERSION = 0.8.3
VERSION = 0.8.4

SOURCES += main.cpp\
mainwindow.cpp \
Expand Down
17 changes: 8 additions & 9 deletions storemodel.cpp
Expand Up @@ -6,6 +6,7 @@
*/
StoreModel::StoreModel()
{
fs = NULL;
}

/**
Expand All @@ -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)
{
Expand All @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions usersdialog.cpp
Expand Up @@ -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()
Expand Down

0 comments on commit e58b9a9

Please sign in to comment.