From 6363384662c34975d2a67ba7f2af24e427addf0b Mon Sep 17 00:00:00 2001 From: Janosch Knack Date: Sat, 26 Nov 2016 20:41:41 +0100 Subject: droppable folders and refactoring --- mainwindow.cpp | 37 ++++--------- mainwindow.h | 1 - mainwindow.ui | 20 ++++++-- qtpasssettings.h | 1 - storemodel.cpp | 154 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- storemodel.h | 25 +++++++++ util.cpp | 22 ++++++++ util.h | 7 ++- 8 files changed, 229 insertions(+), 38 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 943798a0..485eadd4 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -509,25 +509,6 @@ void MainWindow::on_pushButton_clicked() { executeWrapper(QtPassSettings::getGitExecutable(), "push"); } -/** - * @brief MainWindow::getDir get selectd folder path - * @param index - * @param forPass short or full path - * @return path - */ -QString MainWindow::getDir(const QModelIndex &index, bool forPass) { - QString abspath = QDir(QtPassSettings::getPassStore()).absolutePath() + '/'; - if (!index.isValid()) - return forPass ? "" : abspath; - QFileInfo info = model.fileInfo(proxyModel.mapToSource(index)); - QString filePath = - (info.isFile() ? info.absolutePath() : info.absoluteFilePath()); - if (forPass) { - filePath = QDir(abspath).relativeFilePath(filePath); - } - filePath += '/'; - return filePath; -} /** * @brief MainWindow::getFile get the selected file path @@ -554,7 +535,7 @@ QString MainWindow::getFile(const QModelIndex &index, bool forPass) { */ void MainWindow::on_treeView_clicked(const QModelIndex &index) { bool cleared = ui->treeView->currentIndex().flags() == Qt::NoItemFlags; - currentDir = getDir(ui->treeView->currentIndex(), false); + currentDir = Util::getDir(ui->treeView->currentIndex(), false, model, proxyModel); lastDecrypt = "Could not decrypt"; clippedText = ""; QString file = getFile(index, QtPassSettings::isUsePass()); @@ -1093,12 +1074,12 @@ void MainWindow::on_addButton_clicked() { // } bool ok; QString dir = - getDir(ui->treeView->currentIndex(), QtPassSettings::isUsePass()); + Util::getDir(ui->treeView->currentIndex(), QtPassSettings::isUsePass(), model, proxyModel); QString file = QInputDialog::getText( this, tr("New file"), tr("New password file: \n(Will be placed in %1 )") .arg(QtPassSettings::getPassStore() + - getDir(ui->treeView->currentIndex(), true)), + Util::getDir(ui->treeView->currentIndex(), true, model, proxyModel)), QLineEdit::Normal, "", &ok); if (!ok || file.isEmpty()) return; @@ -1146,13 +1127,13 @@ void MainWindow::on_deleteButton_clicked() { } } } else { - file = getDir(ui->treeView->currentIndex(), QtPassSettings::isUsePass()); + file = Util::getDir(ui->treeView->currentIndex(), QtPassSettings::isUsePass(), model,proxyModel); // TODO: message box should accept enter key if (QMessageBox::question( this, tr("Delete folder?"), tr("Are you sure you want to delete %1?") .arg(QDir::separator() + - getDir(ui->treeView->currentIndex(), true)), + Util::getDir(ui->treeView->currentIndex(), true, model, proxyModel)), QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) { return; } else { @@ -1308,7 +1289,7 @@ void MainWindow::on_usersButton_clicked() { } QList selected_users; QString dir = currentDir.isEmpty() - ? getDir(ui->treeView->currentIndex(), false) + ? Util::getDir(ui->treeView->currentIndex(), false, model, proxyModel) : currentDir; int count = 0; QString recipients = @@ -1701,12 +1682,12 @@ void MainWindow::showBrowserContextMenu(const QPoint &pos) { */ void MainWindow::addFolder() { bool ok; - QString dir = getDir(ui->treeView->currentIndex(), false); + QString dir = Util::getDir(ui->treeView->currentIndex(), false, model, proxyModel); QString newdir = QInputDialog::getText( this, tr("New file"), tr("New Folder: \n(Will be placed in %1 )") .arg(QtPassSettings::getPassStore() + - getDir(ui->treeView->currentIndex(), true)), + Util::getDir(ui->treeView->currentIndex(), true, model, proxyModel)), QLineEdit::Normal, "", &ok); if (!ok || newdir.isEmpty()) return; @@ -1726,7 +1707,7 @@ void MainWindow::editPassword() { waitFor(30); process->waitForFinished(); // TODO(annejan) move to editbutton stuff possibly? - currentDir = getDir(ui->treeView->currentIndex(), false); + currentDir = Util::getDir(ui->treeView->currentIndex(), false, model, proxyModel); lastDecrypt = "Could not decrypt"; QString file = getFile(ui->treeView->currentIndex(), QtPassSettings::isUsePass()); diff --git a/mainwindow.h b/mainwindow.h index c2160809..48838882 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -173,7 +173,6 @@ private: void enableUiElements(bool state); void selectFirstFile(); QModelIndex firstFile(QModelIndex parentIndex); - QString getDir(const QModelIndex &, bool); QString getFile(const QModelIndex &, bool); void setPassword(QString, bool, bool); QList listKeys(QString keystring = "", bool secret = false); diff --git a/mainwindow.ui b/mainwindow.ui index ab5c30f4..6c2096bb 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -280,7 +280,17 @@ - + + + true + + + true + + + QAbstractItemView::InternalMove + + @@ -388,10 +398,10 @@ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'.SF NS Text'; font-size:13pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; font-weight:600; color:#333333;">QtPass</span><span style=" font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; color:#333333;"> is a GUI for </span><a href="https://www.passwordstore.org/"><span style=" font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; text-decoration: underline; color:#4183c4; background-color:transparent;">pass</span></a><span style=" font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; color:#333333;">, the standard unix password manager.</span></p> -<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; color:#333333;"><br />Please report any </span><a href="https://github.com/IJHack/qtpass/issues"><span style=" font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; text-decoration: underline; color:#4183c4;">issues</span></a><span style=" font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; color:#333333;"> you might have with this software.</span></p> -<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a href="https://qtpass.org/"><span style=" font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; text-decoration: underline; color:#4183c4; background-color:transparent;">Documentation</span></a></p> +</style></head><body style=" font-family:'Cantarell'; font-size:11pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; font-size:13pt; font-weight:600; color:#333333;">QtPass</span><span style=" font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; font-size:13pt; color:#333333;"> is a GUI for </span><a href="https://www.passwordstore.org/"><span style=" font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; font-size:13pt; text-decoration: underline; color:#4183c4; background-color:transparent;">pass</span></a><span style=" font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; font-size:13pt; color:#333333;">, the standard unix password manager.</span></p> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; font-size:13pt; color:#333333;"><br />Please report any </span><a href="https://github.com/IJHack/qtpass/issues"><span style=" font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; font-size:13pt; text-decoration: underline; color:#4183c4;">issues</span></a><span style=" font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; font-size:13pt; color:#333333;"> you might have with this software.</span></p> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a href="https://qtpass.org/"><span style=" font-family:'Helvetica Neue,Helvetica,Segoe UI,Arial,freesans,sans-serif'; font-size:13pt; text-decoration: underline; color:#4183c4; background-color:transparent;">Documentation</span></a></p> <p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a href="https://github.com/IJHack/qtpass"><span style=" font-family:'Noto Sans'; font-size:12pt; text-decoration: underline; color:#4183c4;">SourceCode</span></a></p></body></html> diff --git a/qtpasssettings.h b/qtpasssettings.h index 3a22235d..74f79d3c 100644 --- a/qtpasssettings.h +++ b/qtpasssettings.h @@ -13,7 +13,6 @@ #include #include "enums.h" -#include "mainwindow.h" class QtPassSettings { diff --git a/storemodel.cpp b/storemodel.cpp index 0b45eb10..65da122e 100644 --- a/storemodel.cpp +++ b/storemodel.cpp @@ -1,4 +1,33 @@ #include "storemodel.h" +#include +#include +#include + + +QDataStream &operator<<(QDataStream &out, const QList &dragAndDropInfoPasswordStores) +{ + foreach (dragAndDropInfoPasswordStore info, dragAndDropInfoPasswordStores) { + out << info.isDir + << info.isFile + << info.path; + } + return out; +} + + + +QDataStream &operator>>(QDataStream &in, QList &dragAndDropInfoPasswordStores) +{ + + while (in.atEnd() == false){ + dragAndDropInfoPasswordStore info; + in >> info.isDir + >> info.isFile + >> info.path; + dragAndDropInfoPasswordStores.append(info); + } + return in; +} /** * @brief StoreModel::StoreModel @@ -41,8 +70,8 @@ bool StoreModel::ShowThis(const QModelIndex index) const { break; } } else { - QModelIndex useIndex = sourceModel()->index(index.row(), 0, index.parent()); - QString path = fs->filePath(useIndex); + QModelIndex useIndex = sourceModel()->index(index.row(), 0, index.parent()); + QString path = fs->filePath(useIndex); path = QDir(store).relativeFilePath(path); path.replace(QRegExp("\\.gpg$"), ""); retVal = path.contains(filterRegExp()); @@ -82,3 +111,124 @@ QVariant StoreModel::data(const QModelIndex &index, int role) const { return initial_value; } + +/** + * @brief StoreModel::supportedDropActions enable drop. + * @return + */ +Qt::DropActions StoreModel::supportedDropActions() const +{ + return Qt::CopyAction | Qt::MoveAction; +} +/** + * @brief StoreModel::supportedDragActions enable drag. + * @return + */ +Qt::DropActions StoreModel::supportedDragActions() const +{ + return Qt::CopyAction | Qt::MoveAction; +} + +Qt::ItemFlags StoreModel::flags(const QModelIndex &index) const +{ + Qt::ItemFlags defaultFlags = QSortFilterProxyModel::flags(index); + + if (index.isValid()){ + return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags; + }else{ + return Qt::ItemIsDropEnabled | defaultFlags; + } +} + +QStringList StoreModel::mimeTypes() const +{ + QStringList types; + types << "application/vnd+qtpass.dragAndDropInfoPasswordStore"; + return types; +} + +QMimeData *StoreModel::mimeData(const QModelIndexList &indexes) const +{ + QList infos; + + foreach (const QModelIndex &index, indexes) { + if (index.isValid()) { + QModelIndex useIndex = mapToSource(index); + + dragAndDropInfoPasswordStore info; + info.isDir = fs->fileInfo(useIndex).isDir(); + info.isFile = fs->fileInfo(useIndex).isFile(); + info.path = fs->fileInfo(useIndex).absoluteFilePath(); + infos.append(info); + } + } + + QByteArray encodedData; + QDataStream stream(&encodedData, QIODevice::WriteOnly); + stream << infos; + + QMimeData *mimeData = new QMimeData(); + mimeData->setData("application/vnd+qtpass.dragAndDropInfoPasswordStore", encodedData); + return mimeData; +} + +bool StoreModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const +{ + QModelIndex useIndex = sourceModel()->index(parent.row(),parent.column(), parent.parent()); + QByteArray encodedData = data->data("application/vnd+qtpass.dragAndDropInfoPasswordStore"); + QDataStream stream(&encodedData, QIODevice::ReadOnly); + QList infos; + stream >> infos; + if (!data->hasFormat("application/vnd+qtpass.dragAndDropInfoPasswordStore")) + return false; + + if (column > 0) + return false; + + return true; +} + +bool StoreModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) +{ + if (!canDropMimeData(data, action, row, column, parent)) + return false; + + if (action == Qt::IgnoreAction){ + return true; + } + QByteArray encodedData = data->data("application/vnd+qtpass.dragAndDropInfoPasswordStore"); + + QDataStream stream(&encodedData, QIODevice::ReadOnly); + QList infos; + stream >> infos; + QModelIndex destIndex = this->index(parent.row(), parent.column(), parent.parent()); + QFileInfo destFileinfo = fs->fileInfo(mapToSource(destIndex)); + + QDir qdir; + foreach (const dragAndDropInfoPasswordStore &info, infos) { + if(info.isDir){ + QDir srcDir = QDir(info.path); + if(destFileinfo.isDir()){ + QString droppedOnDir = destFileinfo.absoluteFilePath(); + QDir destDir = QDir(droppedOnDir).filePath(srcDir.dirName()); + QString cleanedSrcDir = qdir.cleanPath(srcDir.absolutePath()); + QString cleanedDestDir = qdir.cleanPath(destDir.absolutePath()); + if(action == Qt::MoveAction){ + //@todo some error handling + if(QtPassSettings::isUsePass()){ + + }else if(QtPassSettings::isUseGit()){ + + }else{ + qdir.rename(cleanedSrcDir, cleanedDestDir); + } + } + }else if (destFileinfo.isFile()){ + //@todo nothing to here. show dialog. dont drop directories on files + } + }else if(info.isFile){ + + } + } + return true; +} diff --git a/storemodel.h b/storemodel.h index 7407a216..7aeac567 100644 --- a/storemodel.h +++ b/storemodel.h @@ -4,7 +4,12 @@ #include #include #include +#include +#include "util.h" +#include +#include +class Util; /*! \class StoreModel \brief The QSortFilterProxyModel for handling filesystem searches. @@ -15,6 +20,7 @@ private: QFileSystemModel *fs; QString store; + public: StoreModel(); @@ -22,6 +28,25 @@ public: bool ShowThis(const QModelIndex) const; void setModelAndStore(QFileSystemModel *sourceModel, QString passStore); QVariant data(const QModelIndex &index, int role) const; + + // QAbstractItemModel interface +public: + Qt::DropActions supportedDropActions() const; + Qt::DropActions supportedDragActions() const; + Qt::ItemFlags flags(const QModelIndex &index) const; + QStringList mimeTypes() const; + QMimeData *mimeData(const QModelIndexList &indexes) const; + bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const; + bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent); +}; +/*! + \struct dragAndDropInfo + \brief holds values to share beetween drag and drop on the passwordstorage view + */ +struct dragAndDropInfoPasswordStore { + bool isDir; + bool isFile; + QString path; }; #endif // STOREMODEL_H_ diff --git a/util.cpp b/util.cpp index 04be5303..0b399de4 100644 --- a/util.cpp +++ b/util.cpp @@ -136,3 +136,25 @@ void Util::qSleep(int ms) { nanosleep(&ts, NULL); #endif } + +/** + * @brief Util::getDir get selectd folder path + * @param index + * @param forPass short or full path + * @param model the filesystem model to operate on + * @param storeModel our storemodel to operate on + * @return path + */ +QString Util::getDir(const QModelIndex &index, bool forPass, const QFileSystemModel &model, const StoreModel &storeModel) { + QString abspath = QDir(QtPassSettings::getPassStore()).absolutePath() + '/'; + if (!index.isValid()) + return forPass ? "" : abspath; + QFileInfo info = model.fileInfo(storeModel.mapToSource(index)); + QString filePath = + (info.isFile() ? info.absolutePath() : info.absoluteFilePath()); + if (forPass) { + filePath = QDir(abspath).relativeFilePath(filePath); + } + filePath += '/'; + return filePath; +} diff --git a/util.h b/util.h index e12445ae..c160f917 100644 --- a/util.h +++ b/util.h @@ -3,7 +3,12 @@ #include #include +#include +#include "storemodel.h" + + +class StoreModel; /*! \class Util \brief Some static utilities to be used elsewhere. @@ -15,7 +20,7 @@ public: static QString normalizeFolderPath(QString path); static bool checkConfig(); static void qSleep(int ms); - + static QString getDir(const QModelIndex &index, bool forPass, const QFileSystemModel &model, const StoreModel &storeModel); private: static void initialiseEnvironment(); static QProcessEnvironment _env; -- cgit v1.2.3 From 0d61c5603558cbffbd36b5b9df1867ac8d8869fd Mon Sep 17 00:00:00 2001 From: Janosch Knack Date: Sun, 27 Nov 2016 22:32:31 +0100 Subject: refactoring the new pass class --- imitatepass.cpp | 16 ++++++++ imitatepass.h | 7 ++++ mainwindow.cpp | 106 ++++++++++++++++++++--------------------------------- mainwindow.h | 3 -- pass.cpp | 45 +++++++++++++---------- pass.h | 9 +++++ qtpass.pro | 10 ++--- qtpasssettings.cpp | 38 ++++++++++++++++++- qtpasssettings.h | 18 ++++++++- realpass.cpp | 15 ++++++++ realpass.h | 9 +++++ storemodel.cpp | 8 ++-- storemodel.h | 1 - 13 files changed, 182 insertions(+), 103 deletions(-) diff --git a/imitatepass.cpp b/imitatepass.cpp index 4e39bba8..40b7bb24 100644 --- a/imitatepass.cpp +++ b/imitatepass.cpp @@ -282,3 +282,19 @@ void ImitatePass::reencryptPath(QString dir) { } emit endReencryptPath(); } + +void ImitatePass::Move(QDir srcDir, QDir destDir, bool force) +{ +} + +void ImitatePass::Move(QFile srcFile, QFile destFile, bool force) +{ +} + +void ImitatePass::Copy(QDir srcDir, QDir destDir, bool force) +{ +} + +void ImitatePass::Copy(QFile srcFile, QFile destFile, bool force) +{ +} diff --git a/imitatepass.h b/imitatepass.h index cc56cb62..119ad920 100644 --- a/imitatepass.h +++ b/imitatepass.h @@ -25,6 +25,13 @@ signals: void startReencryptPath(); void endReencryptPath(); void lastDecrypt(QString); + + // Pass interface +public: + void Move(QDir srcDir, QDir destDir, bool force = false); + void Move(QFile srcFile, QFile destFile, bool force = false); + void Copy(QDir srcDir, QDir destDir, bool force = false); + void Copy(QFile srcFile, QFile destFile, bool force = false); }; #endif // IMITATEPASS_H diff --git a/mainwindow.cpp b/mainwindow.cpp index fe2ec354..27c8b520 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -34,39 +34,9 @@ */ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), fusedav(this), keygen(NULL), - tray(NULL), pass(nullptr) { + tray(NULL) { // connect(process.data(), SIGNAL(readyReadStandardOutput()), this, // SLOT(readyRead())); - - // TODO(bezet): this should be reconnected dynamically when pass changes - connect(&rpass, SIGNAL(error(QProcess::ProcessError)), this, - SLOT(processError(QProcess::ProcessError))); - connect(&rpass, SIGNAL(finished(int, QProcess::ExitStatus)), this, - SLOT(processFinished(int, QProcess::ExitStatus))); - connect(&rpass, SIGNAL(startingExecuteWrapper()), this, - SLOT(executeWrapperStarted())); - connect(&rpass, SIGNAL(statusMsg(QString, int)), this, - SLOT(showStatusMessage(QString, int))); - connect(&rpass, SIGNAL(critical(QString, QString)), this, - SLOT(critical(QString, QString))); - - connect(&ipass, SIGNAL(error(QProcess::ProcessError)), this, - SLOT(processError(QProcess::ProcessError))); - connect(&ipass, SIGNAL(finished(int, QProcess::ExitStatus)), this, - SLOT(processFinished(int, QProcess::ExitStatus))); - connect(&ipass, SIGNAL(startingExecuteWrapper()), this, - SLOT(executeWrapperStarted())); - connect(&ipass, SIGNAL(statusMsg(QString, int)), this, - SLOT(showStatusMessage(QString, int))); - connect(&ipass, SIGNAL(critical(QString, QString)), this, - SLOT(critical(QString, QString))); - // only for ipass - connect(&ipass, SIGNAL(startReencryptPath()), this, - SLOT(startReencryptPath())); - connect(&ipass, SIGNAL(endReencryptPath()), this, SLOT(endReencryptPath())); - connect(&ipass, SIGNAL(lastDecrypt(QString)), this, - SLOT(setLastDecrypt(QString))); - ui->setupUi(this); enableUiElements(true); execQueue = new QQueue; @@ -100,6 +70,23 @@ MainWindow::MainWindow(QWidget *parent) #if QT_VERSION >= QT_VERSION_CHECK(5,2,0) ui->lineEdit->setClearButtonEnabled(true); #endif + connect(QtPassSettings::getPass(), SIGNAL(error(QProcess::ProcessError)), this, + SLOT(processError(QProcess::ProcessError))); + connect(QtPassSettings::getPass(), SIGNAL(finished(int, QProcess::ExitStatus)), this, + SLOT(processFinished(int, QProcess::ExitStatus))); + connect(QtPassSettings::getPass(), SIGNAL(startingExecuteWrapper()), this, + SLOT(executeWrapperStarted())); + connect(QtPassSettings::getPass(), SIGNAL(statusMsg(QString, int)), this, + SLOT(showStatusMessage(QString, int))); + connect(QtPassSettings::getPass(), SIGNAL(critical(QString, QString)), this, + SLOT(critical(QString, QString))); + + // only for ipass + connect(QtPassSettings::getImitatePass(), SIGNAL(startReencryptPath()), this, + SLOT(startReencryptPath())); + connect(QtPassSettings::getImitatePass(), SIGNAL(endReencryptPath()), this, SLOT(endReencryptPath())); + connect(QtPassSettings::getImitatePass(), SIGNAL(lastDecrypt(QString)), this, + SLOT(setLastDecrypt(QString))); } /** @@ -343,15 +330,7 @@ bool MainWindow::checkConfig() { this, SLOT(showBrowserContextMenu(const QPoint &))); updateProfileBox(); - - // TODO(bezet): make this check unnecessary - if (pass == nullptr) { - if (QtPassSettings::isUsePass()) - pass = &rpass; - else - pass = &ipass; - } - pass->updateEnv(); + QtPassSettings::getPass()->updateEnv(); if (!QtPassSettings::isUseGit() || (QtPassSettings::getGitExecutable().isEmpty() && @@ -381,7 +360,6 @@ void MainWindow::config() { // Automatically default to pass if it's available if (freshStart && QFile(QtPassSettings::getPassExecutable()).exists()) { QtPassSettings::setUsePass(true); - pass = &rpass; } d->setPassPath(QtPassSettings::getPassExecutable()); @@ -429,10 +407,6 @@ void MainWindow::config() { QtPassSettings::setPassStore( Util::normalizeFolderPath(d->getStorePath())); QtPassSettings::setUsePass(d->usePass()); - if (d->usePass()) - pass = &rpass; - else - pass = &ipass; QtPassSettings::setClipBoardType(d->useClipboard()); QtPassSettings::setUseAutoclear(d->useAutoclear()); QtPassSettings::setAutoclearSeconds(d->getAutoclear()); @@ -482,7 +456,7 @@ void MainWindow::config() { if (freshStart && Util::checkConfig()) config(); - pass->updateEnv(); + QtPassSettings::getPass()->updateEnv(); if (!QtPassSettings::isUseGit() || (QtPassSettings::getGitExecutable().isEmpty() && QtPassSettings::getPassExecutable().isEmpty())) { @@ -512,7 +486,7 @@ void MainWindow::config() { void MainWindow::on_updateButton_clicked() { ui->statusBar->showMessage(tr("Updating password-store"), 2000); currentAction = GIT; - pass->GitPull(); + QtPassSettings::getPass()->GitPull(); } /** @@ -521,7 +495,7 @@ void MainWindow::on_updateButton_clicked() { void MainWindow::on_pushButton_clicked() { ui->statusBar->showMessage(tr("Updating password-store"), 2000); currentAction = GIT; - pass->GitPush(); + QtPassSettings::getPass()->GitPush(); } @@ -559,7 +533,7 @@ void MainWindow::on_treeView_clicked(const QModelIndex &index) { ui->passwordName->setText(getFile(index, true)); if (!file.isEmpty() && !cleared) { currentAction = GPG; - pass->Show(file); + QtPassSettings::getPass()->Show(file); } else { clearPanel(false); ui->editButton->setEnabled(false); @@ -605,7 +579,7 @@ void MainWindow::deselect() { */ void MainWindow::executePassGitInit() { qDebug() << "Pass git init called"; - pass->GitInit(); + QtPassSettings::getPass()->GitInit(); } void MainWindow::executeWrapperStarted() { @@ -630,8 +604,8 @@ void MainWindow::readyRead(bool finished = false) { QString output = ""; QString error = ""; if (currentAction != GPG_INTERNAL) { - error = pass->readAllStandardError(); - QByteArray processOutBytes = pass->readAllStandardOutput(); + error = QtPassSettings::getPass()->readAllStandardError(); + QByteArray processOutBytes = QtPassSettings::getPass()->readAllStandardOutput(); QTextCodec *codec = QTextCodec::codecForLocale(); output = codec->toUnicode(processOutBytes); if (finished && currentAction == GPG) { @@ -836,7 +810,7 @@ void MainWindow::processError(QProcess::ProcessError error) { ui->textBrowser->setText(errorString); // TODO(bezet): this probably shall be done in finished handler(I guess it // finishes even on error) - if (pass->state() == QProcess::NotRunning) + if (QtPassSettings::getPass()->state() == QProcess::NotRunning) enableUiElements(true); } @@ -934,7 +908,7 @@ void MainWindow::setPassword(QString file, bool overwrite, bool isNew = false) { newValue += "\n"; currentAction = EDIT; - pass->Insert(file, newValue, overwrite); + QtPassSettings::getPass()->Insert(file, newValue, overwrite); if (QtPassSettings::isUseGit() && QtPassSettings::isAutoPush()) on_pushButton_clicked(); @@ -989,7 +963,7 @@ void MainWindow::on_deleteButton_clicked() { if (fileOrFolder.isFile()) { file = getFile(ui->treeView->currentIndex(), QtPassSettings::isUsePass()); } else { - file = getDir(ui->treeView->currentIndex(), QtPassSettings::isUsePass()); + file = Util::getDir(ui->treeView->currentIndex(), QtPassSettings::isUsePass(), model, proxyModel); isDir = true; } @@ -1002,7 +976,7 @@ void MainWindow::on_deleteButton_clicked() { return; currentAction = REMOVE; - pass->Remove(file, isDir); + QtPassSettings::getPass()->Remove(file, isDir); // TODO(bezet): hide inside interface? if (QtPassSettings::isUseGit() && QtPassSettings::isAutoPush()) on_pushButton_clicked(); @@ -1038,7 +1012,7 @@ void MainWindow::userDialog(QString dir) { // TODO(bezet): temporary wrapper QList MainWindow::listKeys(QString keystring, bool secret) { currentAction = GPG_INTERNAL; - return pass->listKeys(keystring, secret); + return QtPassSettings::getPass()->listKeys(keystring, secret); } /** @@ -1064,7 +1038,7 @@ void MainWindow::on_usersButton_clicked() { : currentDir; int count = 0; QString recipients = - pass->getRecipientString(dir.isEmpty() ? "" : dir, " ", &count); + QtPassSettings::getPass()->getRecipientString(dir.isEmpty() ? "" : dir, " ", &count); if (!recipients.isEmpty()) selected_users = listKeys(recipients); foreach (const UserInfo &sel, selected_users) { @@ -1074,7 +1048,7 @@ void MainWindow::on_usersButton_clicked() { } if (count > selected_users.size()) { // Some keys seem missing from keyring, add them separately - QStringList recipients = pass->getRecipientList(dir.isEmpty() ? "" : dir); + QStringList recipients = QtPassSettings::getPass()->getRecipientList(dir.isEmpty() ? "" : dir); foreach (const QString recipient, recipients) { if (listKeys(recipient).size() < 1) { UserInfo i; @@ -1093,7 +1067,7 @@ void MainWindow::on_usersButton_clicked() { } d.setUsers(NULL); - pass->Init(dir, users); + QtPassSettings::getPass()->Init(dir, users); if (QtPassSettings::isAutoPush()) on_pushButton_clicked(); @@ -1159,7 +1133,7 @@ void MainWindow::generateKeyPair(QString batch, QDialog *keygenWindow) { keygen = keygenWindow; ui->statusBar->showMessage(tr("Generating GPG key pair"), 60000); currentAction = GPG_INTERNAL; - pass->GenerateGPGKeys(batch); + QtPassSettings::getPass()->GenerateGPGKeys(batch); } /** @@ -1202,7 +1176,7 @@ void MainWindow::on_profileBox_currentIndexChanged(QString name) { QtPassSettings::setPassStore(QtPassSettings::getProfiles()[name]); ui->statusBar->showMessage(tr("Profile changed to %1").arg(name), 2000); - pass->resetPasswordStoreDir(); + QtPassSettings::getPass()->resetPasswordStoreDir(); ui->treeView->setRootIndex(proxyModel.mapFromSource( model.setRootPath(QtPassSettings::getPassStore()))); @@ -1389,8 +1363,8 @@ void MainWindow::addFolder() { void MainWindow::editPassword() { if (QtPassSettings::isUseGit() && QtPassSettings::isAutoPull()) on_updateButton_clicked(); - pass->waitFor(30); - pass->waitForProcess(); + QtPassSettings::getPass()->waitFor(30); + QtPassSettings::getPass()->waitForProcess(); // TODO(annejan) move to editbutton stuff possibly? currentDir = Util::getDir(ui->treeView->currentIndex(), false, model, proxyModel); lastDecrypt = "Could not decrypt"; @@ -1398,7 +1372,7 @@ void MainWindow::editPassword() { getFile(ui->treeView->currentIndex(), QtPassSettings::isUsePass()); if (!file.isEmpty()) { currentAction = GPG; - if (pass->Show(file, true) == QProcess::NormalExit) + if (QtPassSettings::getPass()->Show(file, true) == QProcess::NormalExit) on_editButton_clicked(); } } @@ -1424,7 +1398,7 @@ QString MainWindow::generatePassword(int length, "set in the configuration!")); return QString(); } - return pass->Generate(length, pwdConfig.Characters[selection]); + return QtPassSettings::getPass()->Generate(length, pwdConfig.Characters[selection]); } /** diff --git a/mainwindow.h b/mainwindow.h index 6aeade38..11487558 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -155,9 +155,6 @@ private: QString currentDir; bool startupPhase; TrayIcon *tray; - Pass *pass; - RealPass rpass; - ImitatePass ipass; void updateText(); void enableUiElements(bool state); diff --git a/pass.cpp b/pass.cpp index 2e2e7293..5b08ce4c 100644 --- a/pass.cpp +++ b/pass.cpp @@ -3,30 +3,35 @@ #include "util.h" #include + Pass::Pass() : wrapperRunning(false) { - connect(&process, SIGNAL(finished(int, QProcess::ExitStatus)), this, - SIGNAL(finished(int, QProcess::ExitStatus))); - connect(&process, SIGNAL(error(QProcess::ProcessError)), this, - SIGNAL(error(QProcess::ProcessError))); - connect(&process, SIGNAL(finished(int, QProcess::ExitStatus)), this, - SLOT(processFinished(int, QProcess::ExitStatus))); - env = QProcess::systemEnvironment(); +} -#ifdef __APPLE__ - // If it exists, add the gpgtools to PATH - if (QFile("/usr/local/MacGPG2/bin").exists()) - env.replaceInStrings("PATH=", "PATH=/usr/local/MacGPG2/bin:"); - // Add missing /usr/local/bin - if (env.filter("/usr/local/bin").isEmpty()) - env.replaceInStrings("PATH=", "PATH=/usr/local/bin:"); -#endif +void Pass::init(){ + connect(&process, SIGNAL(finished(int, QProcess::ExitStatus)), this, + SIGNAL(finished(int, QProcess::ExitStatus))); + connect(&process, SIGNAL(error(QProcess::ProcessError)), this, + SIGNAL(error(QProcess::ProcessError))); + connect(&process, SIGNAL(finished(int, QProcess::ExitStatus)), this, + SLOT(processFinished(int, QProcess::ExitStatus))); - if (!QtPassSettings::getGpgHome().isEmpty()) { - QDir absHome(QtPassSettings::getGpgHome()); - absHome.makeAbsolute(); - env << "GNUPGHOME=" + absHome.path(); - } + env = QProcess::systemEnvironment(); + + #ifdef __APPLE__ + // If it exists, add the gpgtools to PATH + if (QFile("/usr/local/MacGPG2/bin").exists()) + env.replaceInStrings("PATH=", "PATH=/usr/local/MacGPG2/bin:"); + // Add missing /usr/local/bin + if (env.filter("/usr/local/bin").isEmpty()) + env.replaceInStrings("PATH=", "PATH=/usr/local/bin:"); + #endif + + if (!QtPassSettings::getGpgHome().isEmpty()) { + QDir absHome(QtPassSettings::getGpgHome()); + absHome.makeAbsolute(); + env << "GNUPGHOME=" + absHome.path(); + } } QProcess::ExitStatus Pass::waitForProcess() { diff --git a/pass.h b/pass.h index c56b850f..7a75dce7 100644 --- a/pass.h +++ b/pass.h @@ -5,6 +5,9 @@ #include #include #include +#include +#include + // TODO(bezet): extract UserInfo somewhere #include "enums.h" #include "usersdialog.h" @@ -41,6 +44,8 @@ protected: public: Pass(); + void init(); + virtual ~Pass() {} virtual void GitInit() = 0; virtual void GitPull() = 0; @@ -48,6 +53,10 @@ public: virtual QProcess::ExitStatus Show(QString file, bool block = false) = 0; virtual void Insert(QString file, QString value, bool force) = 0; virtual void Remove(QString file, bool isDir) = 0; + virtual void Move(QDir srcDir, QDir destDir, bool force = false) = 0; + virtual void Move(QFile srcFile, QFile destFile, bool force = false) = 0; + virtual void Copy(QDir srcDir, QDir destDir, bool force = false) = 0; + virtual void Copy(QFile srcFile, QFile destFile, bool force = false) = 0; virtual void Init(QString path, const QList &users) = 0; virtual QString Generate(int length, const QString &charset); diff --git a/qtpass.pro b/qtpass.pro index 79ba42cb..849044ca 100644 --- a/qtpass.pro +++ b/qtpass.pro @@ -36,8 +36,8 @@ SOURCES += main.cpp\ qtpasssettings.cpp \ settingsconstants.cpp \ pass.cpp \ - realpass.cpp \ - imitatepass.cpp + realpass.cpp \ + imitatepass.cpp \ HEADERS += mainwindow.h \ configdialog.h \ @@ -53,9 +53,9 @@ HEADERS += mainwindow.h \ qtpasssettings.h \ enums.h \ settingsconstants.h \ - pass.h \ - realpass.h \ - imitatepass.h + pass.h \ + realpass.h \ + imitatepass.h \ FORMS += mainwindow.ui \ configdialog.ui \ diff --git a/qtpasssettings.cpp b/qtpasssettings.cpp index 529de11d..5a79d7ef 100644 --- a/qtpasssettings.cpp +++ b/qtpasssettings.cpp @@ -1,7 +1,8 @@ #include "qtpasssettings.h" #include "settingsconstants.h" +#include "pass.h" -QtPassSettings::QtPassSettings() {} +QtPassSettings::QtPassSettings(){} bool QtPassSettings::initialized = false; @@ -13,6 +14,10 @@ QHash QtPassSettings::sizeSettings; QHash QtPassSettings::intSettings; QHash QtPassSettings::boolSettings; +Pass* QtPassSettings::pass; +RealPass QtPassSettings::realPass; +ImitatePass QtPassSettings::imitatePass; + QString QtPassSettings::getVersion(const QString &defaultValue) { return getStringValue(SettingsConstants::version, defaultValue); } @@ -119,6 +124,11 @@ bool QtPassSettings::isUsePass(const bool &defaultValue) { } void QtPassSettings::setUsePass(const bool &usePass) { + if(usePass){ + QtPassSettings::pass = &QtPassSettings::realPass; + }else{ + QtPassSettings::pass = &QtPassSettings::imitatePass; + } setBoolValue(SettingsConstants::usePass, usePass); } @@ -602,5 +612,29 @@ QVariant QtPassSettings::getSetting(const QString &key, } void QtPassSettings::setSetting(const QString &key, const QVariant &value) { - getSettings().setValue(key, value); + getSettings().setValue(key, value); +} + +Pass* QtPassSettings::getPass() +{ + if(!pass){ + if(isUsePass()){ + QtPassSettings::pass = &QtPassSettings::realPass; + }else{ + QtPassSettings::pass = &QtPassSettings::imitatePass; + } + pass->init(); + } + return pass; +} + +ImitatePass* QtPassSettings::getImitatePass() +{ + return &imitatePass; +} + +RealPass* QtPassSettings::getRealPass() +{ + return &realPass; } + diff --git a/qtpasssettings.h b/qtpasssettings.h index 8538da60..b80ab8b0 100644 --- a/qtpasssettings.h +++ b/qtpasssettings.h @@ -11,10 +11,13 @@ #include #include #include - +#include "pass.h" +#include "realpass.h" +#include "imitatepass.h" #include "enums.h" -class QtPassSettings { + +class QtPassSettings{ public: static QString @@ -182,6 +185,11 @@ public: static QHash getProfiles(); static void setProfiles(const QHash &profiles); + static Pass* getPass(); + static RealPass* getRealPass(); + static ImitatePass* getImitatePass(); + + signals: public slots: @@ -201,6 +209,11 @@ private: static QHash intSettings; static QHash boolSettings; + static Pass *pass; + static RealPass realPass; + static ImitatePass imitatePass; + + // functions static QSettings &getSettings(); @@ -231,6 +244,7 @@ private: static QVariant getSetting(const QString &key, const QVariant &defaultValue = QVariant()); static void setSetting(const QString &key, const QVariant &value); + }; #endif // QTPASSSETTINGS_H diff --git a/realpass.cpp b/realpass.cpp index a8bab628..6a8c9dcc 100644 --- a/realpass.cpp +++ b/realpass.cpp @@ -78,3 +78,18 @@ void RealPass::Init(QString path, const QList &users) { path.remove(0, QtPassSettings::getPassStore().size()); executePass("init --path=" + dirWithoutPassdir + " " + gpgIds); } +void RealPass::Move(QDir srcDir, QDir destDir, bool force) +{ +} + +void RealPass::Move(QFile srcFile, QFile destFile, bool force) +{ +} + +void RealPass::Copy(QDir srcDir, QDir destDir, bool force) +{ +} + +void RealPass::Copy(QFile srcFile, QFile destFile, bool force) +{ +} diff --git a/realpass.h b/realpass.h index a91a61d8..6f825ab9 100644 --- a/realpass.h +++ b/realpass.h @@ -18,6 +18,15 @@ public: bool overwrite = false) override; virtual void Remove(QString file, bool isDir = false) override; virtual void Init(QString path, const QList &users) override; + + // Pass interface +public: + void Move(QDir srcDir, QDir destDir, bool force = false); + void Move(QFile srcFile, QFile destFile, bool force = false); + void Copy(QDir srcDir, QDir destDir, bool force = false); + void Copy(QFile srcFile, QFile destFile, bool force = false); }; + + #endif // REALPASS_H diff --git a/storemodel.cpp b/storemodel.cpp index 65da122e..b7084160 100644 --- a/storemodel.cpp +++ b/storemodel.cpp @@ -72,9 +72,9 @@ bool StoreModel::ShowThis(const QModelIndex index) const { } else { QModelIndex useIndex = sourceModel()->index(index.row(), 0, index.parent()); QString path = fs->filePath(useIndex); - path = QDir(store).relativeFilePath(path); - path.replace(QRegExp("\\.gpg$"), ""); - retVal = path.contains(filterRegExp()); + path = QDir(store).relativeFilePath(path); + path.replace(QRegExp("\\.gpg$"), ""); + retVal = path.contains(filterRegExp()); } return retVal; } @@ -216,7 +216,7 @@ bool StoreModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int if(action == Qt::MoveAction){ //@todo some error handling if(QtPassSettings::isUsePass()){ - + QtPassSettings::getPass()->Move(QDir(cleanedSrcDir), QDir(cleanedDestDir)); }else if(QtPassSettings::isUseGit()){ }else{ diff --git a/storemodel.h b/storemodel.h index 7aeac567..6f3b2bda 100644 --- a/storemodel.h +++ b/storemodel.h @@ -9,7 +9,6 @@ #include #include -class Util; /*! \class StoreModel \brief The QSortFilterProxyModel for handling filesystem searches. -- cgit v1.2.3 From 8f7561bfe842762d4a8b55e53cda71258230d829 Mon Sep 17 00:00:00 2001 From: Janosch Knack Date: Tue, 29 Nov 2016 07:13:55 +0100 Subject: removing dirs with pass settings, git setting or without any --- imitatepass.cpp | 28 ++++++++++++++++++++++++++++ realpass.cpp | 11 +++++++++++ storemodel.cpp | 8 -------- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/imitatepass.cpp b/imitatepass.cpp index 40b7bb24..a45299da 100644 --- a/imitatepass.cpp +++ b/imitatepass.cpp @@ -285,6 +285,34 @@ void ImitatePass::reencryptPath(QString dir) { void ImitatePass::Move(QDir srcDir, QDir destDir, bool force) { + QString src = srcDir.absolutePath(); + QString dest= destDir.absolutePath(); + if (QtPassSettings::isUseGit()) { + QString args = QString("mv %1 %2 %3"); + // do we need force mode? + if(force){ + args = args.arg("-f"); + }else{ + args = args.arg(""); + } + args = args.arg(src).arg(dest); + executeWrapper(QtPassSettings::getGitExecutable(),args); + + QString args1=QString("commit -m \"moved dir from %1 to %2 using QTPass.\""); + args1= args1.arg(src).arg(dest); + executeWrapper(QtPassSettings::getGitExecutable(), args1); + + if(QtPassSettings::isAutoPush()){ + GitPush(); + } + + } else { + QDir qDir; + if(force){ + qDir.remove(dest); + } + qDir.rename(src, dest); + } } void ImitatePass::Move(QFile srcFile, QFile destFile, bool force) diff --git a/realpass.cpp b/realpass.cpp index 6a8c9dcc..32864263 100644 --- a/realpass.cpp +++ b/realpass.cpp @@ -80,6 +80,17 @@ void RealPass::Init(QString path, const QList &users) { } void RealPass::Move(QDir srcDir, QDir destDir, bool force) { + QString args = QString("mv %1 %2 %3"); + // do we need force mode? + if(force){ + args = args.arg("-f"); + }else{ + args = args.arg(""); + } + QString passSrcDir = QDir(QtPassSettings::getPassStore()).relativeFilePath(srcDir.absolutePath()); + QString passDestDir = QDir(QtPassSettings::getPassStore()).relativeFilePath(destDir.absolutePath()); + args = args.arg(passSrcDir).arg(passDestDir); + executePass(args); } void RealPass::Move(QFile srcFile, QFile destFile, bool force) diff --git a/storemodel.cpp b/storemodel.cpp index b7084160..76356a28 100644 --- a/storemodel.cpp +++ b/storemodel.cpp @@ -18,7 +18,6 @@ QDataStream &operator<<(QDataStream &out, const QList>(QDataStream &in, QList &dragAndDropInfoPasswordStores) { - while (in.atEnd() == false){ dragAndDropInfoPasswordStore info; in >> info.isDir @@ -214,14 +213,7 @@ bool StoreModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int QString cleanedSrcDir = qdir.cleanPath(srcDir.absolutePath()); QString cleanedDestDir = qdir.cleanPath(destDir.absolutePath()); if(action == Qt::MoveAction){ - //@todo some error handling - if(QtPassSettings::isUsePass()){ QtPassSettings::getPass()->Move(QDir(cleanedSrcDir), QDir(cleanedDestDir)); - }else if(QtPassSettings::isUseGit()){ - - }else{ - qdir.rename(cleanedSrcDir, cleanedDestDir); - } } }else if (destFileinfo.isFile()){ //@todo nothing to here. show dialog. dont drop directories on files -- cgit v1.2.3 From 8b01b811089f65def426699e77aceaff0c29119c Mon Sep 17 00:00:00 2001 From: Janosch Knack Date: Tue, 29 Nov 2016 07:33:01 +0100 Subject: now getting "pass" from settings --- mainwindow.cpp | 2 +- passworddialog.cpp | 8 ++++---- passworddialog.h | 3 +-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 5712efd9..9c70f94b 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -893,7 +893,7 @@ void MainWindow::setPassword(QString file, bool overwrite, bool isNew = false) { // warn? return; } - PasswordDialog d(pwdConfig, *pass, this); + PasswordDialog d(pwdConfig, this); d.setFile(file); d.usePwgen(QtPassSettings::isUsePwgen()); d.setTemplate(QtPassSettings::getPassTemplate()); diff --git a/passworddialog.cpp b/passworddialog.cpp index fa00fdb7..c4455ae2 100644 --- a/passworddialog.cpp +++ b/passworddialog.cpp @@ -1,5 +1,6 @@ #include "passworddialog.h" #include "ui_passworddialog.h" +#include "qtpasssettings.h" #include #include #include @@ -9,9 +10,8 @@ * @param parent */ PasswordDialog::PasswordDialog(const passwordConfiguration &passConfig, - Pass &pass, QWidget *parent) - : QDialog(parent), ui(new Ui::PasswordDialog), m_passConfig(passConfig), - m_pass(pass) { + QWidget *parent) + : QDialog(parent), ui(new Ui::PasswordDialog), m_passConfig(passConfig){ templating = false; allFields = false; ui->setupUi(this); @@ -42,7 +42,7 @@ void PasswordDialog::on_checkBoxShow_stateChanged(int arg1) { */ void PasswordDialog::on_createPasswordButton_clicked() { ui->widget->setEnabled(false); - QString newPass = m_pass.Generate( + QString newPass = QtPassSettings::getPass()->Generate( ui->spinBox_pwdLength->value(), m_passConfig.Characters[(passwordConfiguration::characterSet) ui->passwordTemplateSwitch->currentIndex()]); diff --git a/passworddialog.h b/passworddialog.h index 1deb1543..f14c23bc 100644 --- a/passworddialog.h +++ b/passworddialog.h @@ -20,7 +20,7 @@ class PasswordDialog : public QDialog { Q_OBJECT public: - explicit PasswordDialog(const passwordConfiguration &passConfig, Pass &pass, + explicit PasswordDialog(const passwordConfiguration &passConfig, QWidget *parent = 0); ~PasswordDialog(); @@ -59,7 +59,6 @@ private slots: private: Ui::PasswordDialog *ui; const passwordConfiguration &m_passConfig; - Pass &m_pass; QString passTemplate; QStringList fields; bool templating; -- cgit v1.2.3 From 7a90685ea7cdb95f6461539a7fddc2b2655b4b35 Mon Sep 17 00:00:00 2001 From: Janosch Knack Date: Thu, 1 Dec 2016 16:24:22 +0100 Subject: move files wrapper for gpg and git --- imitatepass.cpp | 91 +++++++++++++++++++++++-------------------- imitatepass.h | 6 +-- pass.cpp | 26 +++++++++++++ pass.h | 12 +++--- realpass.cpp | 48 ++++++++++++++--------- realpass.h | 9 +---- storemodel.cpp | 117 +++++++++++++++++++++++++++++++------------------------- 7 files changed, 179 insertions(+), 130 deletions(-) diff --git a/imitatepass.cpp b/imitatepass.cpp index a45299da..1e05b7dd 100644 --- a/imitatepass.cpp +++ b/imitatepass.cpp @@ -8,22 +8,23 @@ ImitatePass::ImitatePass() {} * @brief ImitatePass::GitInit git init wrapper */ void ImitatePass::GitInit() { - executeWrapper(QtPassSettings::getGitExecutable(), - "init \"" + QtPassSettings::getPassStore() + '"'); + executeGit("init \"" + QtPassSettings::getPassStore() + '"'); } /** * @brief ImitatePass::GitPull git init wrapper */ void ImitatePass::GitPull() { - executeWrapper(QtPassSettings::getGitExecutable(), "pull"); + executeGit("pull"); } /** * @brief ImitatePass::GitPush git init wrapper */ void ImitatePass::GitPush() { - executeWrapper(QtPassSettings::getGitExecutable(), "push"); + if(QtPassSettings::isUseGit()){ + executeGit("push"); + } } /** @@ -32,8 +33,7 @@ void ImitatePass::GitPush() { QProcess::ExitStatus ImitatePass::Show(QString file, bool block) { // TODO(bezet): apparently not yet needed // file += ".gpg"; - executeWrapper(QtPassSettings::getGpgExecutable(), - "-d --quiet --yes --no-encrypt-to --batch --use-agent \"" + + executeGpg("-d --quiet --yes --no-encrypt-to --batch --use-agent \"" + file + '"'); if (block) return waitForProcess(); @@ -59,17 +59,15 @@ void ImitatePass::Insert(QString file, QString newValue, bool overwrite) { return; } QString force(overwrite ? " --yes " : " "); - executeWrapper(QtPassSettings::getGpgExecutable(), - force + "--batch -eq --output \"" + file + "\" " + recipients + + executeGpg(force + "--batch -eq --output \"" + file + "\" " + recipients + " -", newValue); if (!QtPassSettings::isUseWebDav() && QtPassSettings::isUseGit()) { if (!overwrite) - executeWrapper(QtPassSettings::getGitExecutable(), "add \"" + file + '"'); + executeGit("add \"" + file + '"'); QString path = QDir(QtPassSettings::getPassStore()).relativeFilePath(file); path.replace(QRegExp("\\.gpg$"), ""); - executeWrapper(QtPassSettings::getGitExecutable(), - "commit \"" + file + "\" -m \"" + + executeGit("commit \"" + file + "\" -m \"" + (overwrite ? "Edit" : "Add") + " for " + path + " using QtPass.\""); } @@ -80,13 +78,11 @@ void ImitatePass::Insert(QString file, QString newValue, bool overwrite) { */ void ImitatePass::Remove(QString file, bool isDir) { if (QtPassSettings::isUseGit()) { - executeWrapper(QtPassSettings::getGitExecutable(), - QString("rm ") + (isDir ? "-rf " : "-f ") + '"' + file + + executeGit(QString("rm ") + (isDir ? "-rf " : "-f ") + '"' + file + '"'); // TODO(bezet): commit message used to have pass-like file name inside(ie. // getFile(file, true) - executeWrapper(QtPassSettings::getGitExecutable(), - "commit \"" + file + "\" -m \"Remove for " + file + + executeGit("commit \"" + file + "\" -m \"Remove for " + file + " using QtPass.\""); } else { if (isDir) { @@ -140,12 +136,10 @@ void ImitatePass::Init(QString path, const QList &users) { if (!QtPassSettings::isUseWebDav() && QtPassSettings::isUseGit() && !QtPassSettings::getGitExecutable().isEmpty()) { if (addFile) - executeWrapper(QtPassSettings::getGitExecutable(), - "add \"" + gpgIdFile + '"'); + executeGit("add \"" + gpgIdFile + '"'); QString path = gpgIdFile; path.replace(QRegExp("\\.gpg$"), ""); - executeWrapper(QtPassSettings::getGitExecutable(), - "commit \"" + gpgIdFile + "\" -m \"Added " + path + + executeGit("commit \"" + gpgIdFile + "\" -m \"Added " + path + " using QtPass.\""); } reencryptPath(path); @@ -206,8 +200,7 @@ void ImitatePass::reencryptPath(QString dir) { gpgId.sort(); } process.waitForFinished(); - executeWrapper(QtPassSettings::getGpgExecutable(), - "-v --no-secmem-warning " + executeGpg( "-v --no-secmem-warning " "--no-permission-warning --list-only " "--keyid-format long " + fileName); @@ -233,8 +226,7 @@ void ImitatePass::reencryptPath(QString dir) { qDebug() << "reencrypt " << fileName << " for " << gpgId; QString local_lastDecrypt = "Could not decrypt"; emit lastDecrypt(local_lastDecrypt); - executeWrapper(QtPassSettings::getGpgExecutable(), - "-d --quiet --yes --no-encrypt-to --batch --use-agent \"" + + executeGpg("-d --quiet --yes --no-encrypt-to --batch --use-agent \"" + fileName + '"'); process.waitForFinished(30000); // long wait (passphrase stuff) local_lastDecrypt = process.readAllStandardOutput(); @@ -253,20 +245,18 @@ void ImitatePass::reencryptPath(QString dir) { "file missing or invalid.")); return; } - executeWrapper(QtPassSettings::getGpgExecutable(), + executeGpg( "--yes --batch -eq --output \"" + fileName + "\" " + recipients + " -", local_lastDecrypt); process.waitForFinished(3000); if (!QtPassSettings::isUseWebDav() && QtPassSettings::isUseGit()) { - executeWrapper(QtPassSettings::getGitExecutable(), - "add \"" + fileName + '"'); + executeGit("add \"" + fileName + '"'); QString path = QDir(QtPassSettings::getPassStore()).relativeFilePath(fileName); path.replace(QRegExp("\\.gpg$"), ""); - executeWrapper(QtPassSettings::getGitExecutable(), - "commit \"" + fileName + "\" -m \"" + "Edit for " + + executeGit("commit \"" + fileName + "\" -m \"" + "Edit for " + path + " using QtPass.\""); process.waitForFinished(3000); } @@ -283,24 +273,22 @@ void ImitatePass::reencryptPath(QString dir) { emit endReencryptPath(); } -void ImitatePass::Move(QDir srcDir, QDir destDir, bool force) +void ImitatePass::Move(const QString src, const QString dest, const bool force) { - QString src = srcDir.absolutePath(); - QString dest= destDir.absolutePath(); if (QtPassSettings::isUseGit()) { QString args = QString("mv %1 %2 %3"); - // do we need force mode? + // force mode? if(force){ args = args.arg("-f"); }else{ args = args.arg(""); } args = args.arg(src).arg(dest); - executeWrapper(QtPassSettings::getGitExecutable(),args); + executeGit(args); - QString args1=QString("commit -m \"moved dir from %1 to %2 using QTPass.\""); + QString args1=QString("commit -m \"moved from %1 to %2 using QTPass.\""); args1= args1.arg(src).arg(dest); - executeWrapper(QtPassSettings::getGitExecutable(), args1); + executeGit(args1); if(QtPassSettings::isAutoPush()){ GitPush(); @@ -315,14 +303,33 @@ void ImitatePass::Move(QDir srcDir, QDir destDir, bool force) } } -void ImitatePass::Move(QFile srcFile, QFile destFile, bool force) -{ -} -void ImitatePass::Copy(QDir srcDir, QDir destDir, bool force) +void ImitatePass::Copy(const QString src, const QString dest, const bool force) { -} + if (QtPassSettings::isUseGit()) { + QString args = QString("cp %1 %2 %3"); + // do we need force mode? + if(force){ + args = args.arg("-f"); + }else{ + args = args.arg(""); + } + args = args.arg(src).arg(dest); + executeGit(args); -void ImitatePass::Copy(QFile srcFile, QFile destFile, bool force) -{ + QString args1=QString("commit -m \"copied from %1 to %2 using QTPass.\""); + args1= args1.arg(src).arg(dest); + executeGit(args1); + + if(QtPassSettings::isAutoPush()){ + GitPush(); + } + + } else { + QDir qDir; + if(force){ + qDir.remove(dest); + } + qDir.rename(src, dest); + } } diff --git a/imitatepass.h b/imitatepass.h index 119ad920..04ef2235 100644 --- a/imitatepass.h +++ b/imitatepass.h @@ -28,10 +28,8 @@ signals: // Pass interface public: - void Move(QDir srcDir, QDir destDir, bool force = false); - void Move(QFile srcFile, QFile destFile, bool force = false); - void Copy(QDir srcDir, QDir destDir, bool force = false); - void Copy(QFile srcFile, QFile destFile, bool force = false); + void Move(const QString src, const QString dest, const bool force = false); + void Copy(const QString src, const QString dest, const bool force = false); }; #endif // IMITATEPASS_H diff --git a/pass.cpp b/pass.cpp index 5dcf4c5a..3f7cb28a 100644 --- a/pass.cpp +++ b/pass.cpp @@ -314,3 +314,29 @@ QString Pass::getRecipientString(QString for_file, QString separator, recipients_str += separator + '"' + recipient + '"'; return recipients_str; } + +/** + * @brief Pass::executePass easy wrapper for running pass + * @param args + */ +void Pass::executePass(QString args, QString input) { + executeWrapper(QtPassSettings::getPassExecutable(), args, input); +} + +/** + * @brief Pass::executeGpg easy wrapper for running gpg commands + * @param args + */ +void Pass::executeGpg(QString args, QString input) +{ + executeWrapper(QtPassSettings::getGpgExecutable(), args, input); +} +/** + * @brief Pass::executeGit easy wrapper for running git commands + * @param args + */ +void Pass::executeGit(QString args, QString input) { + executeWrapper(QtPassSettings::getGitExecutable(), args, input); +} + + diff --git a/pass.h b/pass.h index c0c8d148..8035533f 100644 --- a/pass.h +++ b/pass.h @@ -40,8 +40,9 @@ class Pass : public QObject { bool wrapperRunning; QStringList env; -protected: +private : void executeWrapper(QString, QString, QString = QString()); +protected: QProcess process; public: @@ -55,10 +56,8 @@ public: virtual QProcess::ExitStatus Show(QString file, bool block = false) = 0; virtual void Insert(QString file, QString value, bool force) = 0; virtual void Remove(QString file, bool isDir) = 0; - virtual void Move(QDir srcDir, QDir destDir, bool force = false) = 0; - virtual void Move(QFile srcFile, QFile destFile, bool force = false) = 0; - virtual void Copy(QDir srcDir, QDir destDir, bool force = false) = 0; - virtual void Copy(QFile srcFile, QFile destFile, bool force = false) = 0; + virtual void Move(const QString srcDir, const QString dest, const bool force = false) = 0; + virtual void Copy(const QString srcDir, const QString dest, const bool force = false) = 0; virtual void Init(QString path, const QList &users) = 0; virtual QString Generate(int length, const QString &charset); @@ -77,6 +76,9 @@ public: static QString getRecipientString(QString for_file, QString separator = " ", int *count = NULL); + void executeGit(QString args, QString input = QString()); + void executePass(QString args, QString input = QString()); + void executeGpg(QString args, QString input = QString()); private slots: void processFinished(int, QProcess::ExitStatus); diff --git a/realpass.cpp b/realpass.cpp index 32864263..62f5d56d 100644 --- a/realpass.cpp +++ b/realpass.cpp @@ -3,13 +3,7 @@ RealPass::RealPass() {} -/** - * @brief RealPass::executePass easy wrapper for running pass - * @param args - */ -void RealPass::executePass(QString args, QString input) { - executeWrapper(QtPassSettings::getPassExecutable(), args, input); -} + /** * @brief RealPass::GitInit git init wrapper @@ -78,29 +72,45 @@ void RealPass::Init(QString path, const QList &users) { path.remove(0, QtPassSettings::getPassStore().size()); executePass("init --path=" + dirWithoutPassdir + " " + gpgIds); } -void RealPass::Move(QDir srcDir, QDir destDir, bool force) +void RealPass::Move(const QString src, const QString dest, const bool force) { QString args = QString("mv %1 %2 %3"); - // do we need force mode? + // force mode? if(force){ args = args.arg("-f"); }else{ args = args.arg(""); } - QString passSrcDir = QDir(QtPassSettings::getPassStore()).relativeFilePath(srcDir.absolutePath()); - QString passDestDir = QDir(QtPassSettings::getPassStore()).relativeFilePath(destDir.absolutePath()); - args = args.arg(passSrcDir).arg(passDestDir); + QString passSrc = QDir(QtPassSettings::getPassStore()).relativeFilePath(QDir(src).absolutePath()); + QString passDest= QDir(QtPassSettings::getPassStore()).relativeFilePath(QDir(dest).absolutePath()); + QFileInfo srcFileInfo= QFileInfo(src); + QFileInfo destFileInfo= QFileInfo(dest); + + // remove the .gpg because pass will not work + if(srcFileInfo.isFile() && srcFileInfo.suffix() == "gpg"){ + passSrc.replace(QRegExp("\\.gpg$"), ""); + } + if(destFileInfo.isFile() && destFileInfo.suffix() == "gpg"){ + passDest.replace(QRegExp("\\.gpg$"), ""); + } + + args = args.arg(passSrc).arg(passDest); executePass(args); } -void RealPass::Move(QFile srcFile, QFile destFile, bool force) -{ -} -void RealPass::Copy(QDir srcDir, QDir destDir, bool force) +void RealPass::Copy(const QString src, const QString dest, const bool force) { + QString args = QString("cp %1 %2 %3"); + // do we need force mode? + if(force){ + args = args.arg("-f"); + }else{ + args = args.arg(""); + } + QString passSrc = QDir(QtPassSettings::getPassStore()).relativeFilePath(QDir(src).absolutePath()); + QString passDest= QDir(QtPassSettings::getPassStore()).relativeFilePath(QDir(dest).absolutePath()); + args = args.arg(passSrc).arg(passDest); + executePass(args); } -void RealPass::Copy(QFile srcFile, QFile destFile, bool force) -{ -} diff --git a/realpass.h b/realpass.h index 6f825ab9..5fdaa679 100644 --- a/realpass.h +++ b/realpass.h @@ -4,9 +4,6 @@ #include "pass.h" class RealPass : public Pass { -private: - void executePass(QString args, QString input = QString()); - public: RealPass(); virtual ~RealPass() {} @@ -21,10 +18,8 @@ public: // Pass interface public: - void Move(QDir srcDir, QDir destDir, bool force = false); - void Move(QFile srcFile, QFile destFile, bool force = false); - void Copy(QDir srcDir, QDir destDir, bool force = false); - void Copy(Q