diff options
author | tezeb <tezeb+github@outoftheblue.pl> | 2017-01-11 00:03:57 +0100 |
---|---|---|
committer | tezeb <tezeb+github@outoftheblue.pl> | 2017-01-11 00:03:57 +0100 |
commit | d12d945631ce76bf90bfc7a6c1efd1db498c65d4 (patch) | |
tree | a3c321e72e1803a63c4c1b8c1e633abde2938f3b /src | |
parent | 12c08eaf8ca35cec9248ac1353e1651b84688fa1 (diff) |
use signal based communication in MainWindow
Diffstat (limited to 'src')
-rw-r--r-- | src/mainwindow.cpp | 82 | ||||
-rw-r--r-- | src/mainwindow.h | 3 |
2 files changed, 48 insertions, 37 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 8d438135..06232102 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -44,50 +44,15 @@ MainWindow::MainWindow(QWidget *parent) new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this, SLOT(close())); // TODO(bezet): this should be reconnected dynamically when pass changes - connect(QtPassSettings::getRealPass(), SIGNAL(error(QProcess::ProcessError)), - this, SLOT(processError(QProcess::ProcessError))); - connect(QtPassSettings::getRealPass(), &Pass::finishedAny, this, - &MainWindow::processFinished); - connect(QtPassSettings::getRealPass(), SIGNAL(startingExecuteWrapper()), this, - SLOT(executeWrapperStarted())); - connect(QtPassSettings::getRealPass(), SIGNAL(statusMsg(QString, int)), this, - SLOT(showStatusMessage(QString, int))); - connect(QtPassSettings::getRealPass(), SIGNAL(critical(QString, QString)), - this, SLOT(critical(QString, QString))); - - /* NEW */ - connect(QtPassSettings::getRealPass(), &Pass::finishedShow, this, - &MainWindow::passShowHandler); - connect(QtPassSettings::getRealPass(), &Pass::processErrorExit, this, - &MainWindow::processErrorExit); - connect(QtPassSettings::getRealPass(), &Pass::finishedGenerateGPGKeys, this, - &MainWindow::keyGenerationComplete); + connectPassSignalHandlers(QtPassSettings::getRealPass()); + connectPassSignalHandlers(QtPassSettings::getImitatePass()); - connect(QtPassSettings::getImitatePass(), - SIGNAL(error(QProcess::ProcessError)), this, - SLOT(processError(QProcess::ProcessError))); - connect(QtPassSettings::getImitatePass(), &Pass::finishedAny, this, - &MainWindow::processFinished); - connect(QtPassSettings::getImitatePass(), SIGNAL(startingExecuteWrapper()), - this, SLOT(executeWrapperStarted())); - connect(QtPassSettings::getImitatePass(), SIGNAL(statusMsg(QString, int)), - this, SLOT(showStatusMessage(QString, int))); - connect(QtPassSettings::getImitatePass(), 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())); - /* NEW */ - connect(QtPassSettings::getImitatePass(), &Pass::finishedShow, this, - &MainWindow::passShowHandler); - connect(QtPassSettings::getImitatePass(), &Pass::processErrorExit, this, - &MainWindow::processErrorExit); - connect(QtPassSettings::getImitatePass(), &Pass::finishedGenerateGPGKeys, - this, &MainWindow::keyGenerationComplete); - ui->setupUi(this); enableUiElements(true); ui->statusBar->showMessage(tr("Welcome to QtPass %1").arg(VERSION), 2000); @@ -168,6 +133,38 @@ void MainWindow::changeEvent(QEvent *event) { } /** + * @brief MainWindow::connectPassSignalHandlers this method connects Pass + * signals to approprite MainWindow + * slots + * + * @param pass pointer to pass instance + */ +void MainWindow::connectPassSignalHandlers(Pass *pass) { + + // TODO(bezet): this is never emitted(should be), also naming(see + // critical()) + connect(pass, &Pass::error, this, &MainWindow::processError); + connect(pass, &Pass::startingExecuteWrapper, this, + &MainWindow::executeWrapperStarted); + connect(pass, &Pass::critical, this, &MainWindow::critical); + connect(pass, &Pass::statusMsg, this, &MainWindow::showStatusMessage); + connect(pass, &Pass::processErrorExit, this, &MainWindow::processErrorExit); + + connect(pass, &Pass::finishedGitInit, this, &MainWindow::passStoreChanged); + connect(pass, &Pass::finishedGitPull, this, &MainWindow::processFinished); + connect(pass, &Pass::finishedGitPush, this, &MainWindow::processFinished); + connect(pass, &Pass::finishedShow, this, &MainWindow::passShowHandler); + connect(pass, &Pass::finishedInsert, this, &MainWindow::finishedInsert); + connect(pass, &Pass::finishedRemove, this, &MainWindow::passStoreChanged); + connect(pass, &Pass::finishedInit, this, &MainWindow::passStoreChanged); + connect(pass, &Pass::finishedMove, this, &MainWindow::passStoreChanged); + connect(pass, &Pass::finishedCopy, this, &MainWindow::passStoreChanged); + + connect(pass, &Pass::finishedGenerateGPGKeys, this, + &MainWindow::keyGenerationComplete); +} + +/** * @brief MainWindow::mountWebDav is some scary voodoo magic */ void MainWindow::mountWebDav() { @@ -711,9 +708,20 @@ void MainWindow::passShowHandler(const QString &p_output) { enableUiElements(true); } +void MainWindow::passStoreChanged(const QString &p_out, const QString &p_err) { + processFinished(p_out, p_err); + doGitPush(); +} + +void MainWindow::doGitPush() { + if (QtPassSettings::isAutoPush()) + on_pushButton_clicked(); +} + void MainWindow::finishedInsert(const QString &p_output, const QString &p_errout) { processFinished(p_output, p_errout); + doGitPush(); on_treeView_clicked(ui->treeView->currentIndex()); } diff --git a/src/mainwindow.h b/src/mainwindow.h index 6e50ec5d..7122a5b3 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -102,6 +102,8 @@ private slots: void endReencryptPath(); void critical(QString, QString); void passShowHandler(const QString &); + void passStoreChanged(const QString &, const QString &); + void doGitPush(); void processErrorExit(int exitCode, const QString &); @@ -146,6 +148,7 @@ private: const QString &value); void DisplayInTextBrowser(QString toShow, QString prefix = QString(), QString postfix = QString()); + void connectPassSignalHandlers(Pass *pass); }; #endif // MAINWINDOW_H_ |