Skip to content

Commit

Permalink
Merge pull request #477 from maciejsszmigiero/main-window-entry-detai…
Browse files Browse the repository at this point in the history
…ls-improvements

Main window entry details improvements
  • Loading branch information
annejan authored Sep 28, 2019
2 parents df43cec + 0498dd6 commit 37472bc
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 18 deletions.
21 changes: 17 additions & 4 deletions src/filecontent.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
#include "filecontent.h"

static bool isLineHidden(const QString &line) {
return line.startsWith("otpauth://", Qt::CaseInsensitive);
}

FileContent FileContent::parse(const QString &fileContent,
const QStringList &templateFields,
bool allFields) {
QStringList lines = fileContent.split("\n");
QString password = lines.takeFirst();
QStringList remainingData;
QStringList remainingData, remainingDataDisplay;
NamedValues namedValues;
for (const QString &line : lines) {
if (line.contains(":")) {
Expand All @@ -20,9 +24,13 @@ FileContent FileContent::parse(const QString &fileContent,
continue;
}
}

remainingData.append(line);
if (!isLineHidden(line))
remainingDataDisplay.append(line);
}
return FileContent(password, namedValues, remainingData.join("\n"));
return FileContent(password, namedValues, remainingData.join("\n"),
remainingDataDisplay.join("\n"));
}

QString FileContent::getPassword() const { return this->password; }
Expand All @@ -31,11 +39,16 @@ NamedValues FileContent::getNamedValues() const { return this->namedValues; }

QString FileContent::getRemainingData() const { return this->remainingData; }

QString FileContent::getRemainingDataForDisplay() const {
return this->remainingDataDisplay;
}

FileContent::FileContent(const QString &password,
const NamedValues &namedValues,
const QString &remainingData)
const QString &remainingData,
const QString &remainingDataDisplay)
: password(password), namedValues(namedValues),
remainingData(remainingData) {}
remainingData(remainingData), remainingDataDisplay(remainingDataDisplay) {}

NamedValues::NamedValues() : QList() {}

Expand Down
14 changes: 10 additions & 4 deletions src/filecontent.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class FileContent {
* @brief parse parses the given fileContent in a FileContent object.
* The password is accessible through getPassword.
* The named value pairs (name: value) are parsed and depeding on the
* templateFields and allFields parameters accessible through getNamedValues
* or getRemainingData.
* templateFields and allFields parameters accessible through getNamedValues,
* getRemainingData or getRemainingDataForDisplay.
*
* @param fileContent the file content to parse.
*
Expand Down Expand Up @@ -61,13 +61,19 @@ class FileContent {
*/
QString getRemainingData() const;

/**
* @like getRemainingData but without data that should not be displayed
* (like a TOTP secret).
*/
QString getRemainingDataForDisplay() const;

private:
FileContent(const QString &password, const NamedValues &namedValues,
const QString &remainingData);
const QString &remainingData, const QString &remainingDataDisplay);

QString password;
NamedValues namedValues;
QString remainingData;
QString remainingData, remainingDataDisplay;
};

#endif // FILECONTENT_H
8 changes: 3 additions & 5 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,6 @@ void MainWindow::cleanKeygenDialog() {
this->keygen = nullptr;
}

void MainWindow::setTextTextBrowser(const QString &text) {
ui->textBrowser->setText(text);
}

void MainWindow::flashText(const QString &text, const bool isError,
const bool isHtml) {
if (isError)
Expand Down Expand Up @@ -403,13 +399,15 @@ void MainWindow::passShowHandler(const QString &p_output) {
ui->verticalLayoutPassword->setSpacing(0);
else
ui->verticalLayoutPassword->setSpacing(6);
output = fileContent.getRemainingData();

output = fileContent.getRemainingDataForDisplay();
}

if (QtPassSettings::isUseAutoclearPanel()) {
clearPanelTimer.start();
}

emit passShowHandlerFinished(output);
setUiElementsEnabled(true);
}

Expand Down
2 changes: 0 additions & 2 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class MainWindow : public QMainWindow {
void userDialog(QString = "");
void config();

void setTextTextBrowser(const QString &text);
void setUiElementsEnabled(bool state);
void flashText(const QString &text, const bool isError,
const bool isHtml = false);
Expand All @@ -66,7 +65,6 @@ class MainWindow : public QMainWindow {
bool eventFilter(QObject *obj, QEvent *event);

signals:
void uiEnabled(bool state);
void passShowHandlerFinished(QString output);
void passGitInitNeeded();
void generateGPGKeyPair(QString batch);
Expand Down
6 changes: 3 additions & 3 deletions src/qtpass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ void QtPass::setMainWindow(MainWindow *mW) {
connectPassSignalHandlers(QtPassSettings::getRealPass());
connectPassSignalHandlers(QtPassSettings::getImitatePass());

connect(m_mainWindow, &MainWindow::passShowHandlerFinished, this,
&QtPass::passShowHandlerFinished);

// only for ipass
connect(QtPassSettings::getImitatePass(), &ImitatePass::startReencryptPath,
m_mainWindow, &MainWindow::startReencryptPath);
Expand All @@ -144,13 +147,10 @@ void QtPass::setMainWindow(MainWindow *mW) {
void QtPass::connectPassSignalHandlers(Pass *pass) {
connect(pass, &Pass::error, this, &QtPass::processError);
connect(pass, &Pass::processErrorExit, this, &QtPass::processErrorExit);

connect(pass, &Pass::critical, m_mainWindow, &MainWindow::critical);
connect(pass, &Pass::startingExecuteWrapper, m_mainWindow,
&MainWindow::executeWrapperStarted);
connect(pass, &Pass::statusMsg, m_mainWindow, &MainWindow::showStatusMessage);
connect(m_mainWindow, &MainWindow::passShowHandlerFinished, this,
&QtPass::passShowHandlerFinished);
connect(pass, &Pass::finishedShow, m_mainWindow,
&MainWindow::passShowHandler);
connect(pass, &Pass::finishedOtpGenerate, m_mainWindow,
Expand Down

0 comments on commit 37472bc

Please sign in to comment.