Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable apply button to workaround data loss issue #2204

Merged
merged 2 commits into from
Aug 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions src/gui/EditWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,14 @@ QLabel* EditWidget::headlineLabel()
return m_ui->headerLabel;
}

void EditWidget::setReadOnly(bool readOnly)
void EditWidget::setReadOnly(bool readOnly, bool applyEnabled)
{
m_readOnly = readOnly;

if (readOnly) {
m_ui->buttonBox->setStandardButtons(QDialogButtonBox::Close);
}
else {
m_ui->buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Apply);
// Find and connect the apply button
QPushButton* applyButton = m_ui->buttonBox->button(QDialogButtonBox::Apply);
connect(applyButton, SIGNAL(clicked()), SIGNAL(apply()));
} else {
setupButtons(applyEnabled);
}
}

Expand All @@ -117,6 +113,19 @@ bool EditWidget::readOnly() const
return m_readOnly;
}

void EditWidget::setupButtons(bool applyEnabled)
{
if (applyEnabled) {
m_ui->buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Apply);
// Find and connect the apply button
QPushButton* applyButton = m_ui->buttonBox->button(QDialogButtonBox::Apply);
connect(applyButton, SIGNAL(clicked()), SIGNAL(apply()));
} else {
m_ui->buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
disconnect(SIGNAL(apply()));
}
}

void EditWidget::showMessage(const QString& text, MessageWidget::MessageType type)
{
m_ui->messageWidget->setCloseButtonVisible(false);
Expand Down
4 changes: 3 additions & 1 deletion src/gui/EditWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class EditWidget : public DialogyWidget
void setCurrentPage(int index);
void setHeadline(const QString& text);
QLabel* headlineLabel();
void setReadOnly(bool readOnly);
void setReadOnly(bool readOnly, bool applyEnabled = true);
bool readOnly() const;

signals:
Expand All @@ -58,6 +58,8 @@ protected slots:
void hideMessage();

private:
void setupButtons(bool applyEnabled);

const QScopedPointer<Ui::EditWidget> m_ui;
bool m_readOnly;

Expand Down
6 changes: 5 additions & 1 deletion src/gui/EditWidgetIcons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ UrlFetchProgressDialog::UrlFetchProgressDialog(const QUrl &url, QWidget *parent)

void UrlFetchProgressDialog::networkReplyProgress(qint64 bytesRead, qint64 totalBytes)
{
setValue(static_cast<int>(bytesRead / totalBytes));
if (totalBytes > 0) {
setValue(static_cast<int>(bytesRead / totalBytes));
} else {
setValue(0);
}
}

EditWidgetIcons::EditWidgetIcons(QWidget* parent)
Expand Down
4 changes: 2 additions & 2 deletions src/gui/entry/EditEntryWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,8 @@ void EditEntryWidget::loadEntry(Entry* entry, bool create, bool history, const Q
}

setForms(entry);
setReadOnly(m_history);
// Disable apply button if creating new entry (#2191)
setReadOnly(m_history, !m_create);

setCurrentPage(0);
setPageHidden(m_historyWidget, m_history || m_entry->historyItems().count() < 1);
Expand Down Expand Up @@ -802,7 +803,6 @@ void EditEntryWidget::acceptEntry()
{
if (commitEntry()) {
clear();
hideMessage();
emit editFinished(true);
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/gui/group/EditGroupWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ void EditGroupWidget::loadGroup(Group* group, bool create, Database* database)

if (create) {
setHeadline(tr("Add group"));
}
else {
} else {
setHeadline(tr("Edit group"));
}

Expand Down Expand Up @@ -99,6 +98,9 @@ void EditGroupWidget::loadGroup(Group* group, bool create, Database* database)

setCurrentPage(0);

// Disable apply button if creating new group
setReadOnly(false, create);

m_mainUi->editName->setFocus();
}

Expand Down
8 changes: 6 additions & 2 deletions tests/gui/TestGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,9 @@ void TestGui::testAddEntry()
QTest::keyClicks(passwordRepeatEdit, "something 2");
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);

/* All apply tests disabled due to data loss workaround
* that disables apply button on new entry creation
*
// Add entry "something 3" using the apply button then click ok
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
QTest::keyClicks(titleEdit, "something 3");
Expand All @@ -488,6 +491,7 @@ void TestGui::testAddEntry()
QTest::keyClicks(titleEdit, "something 4");
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Apply), Qt::LeftButton);
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Cancel), Qt::LeftButton);
*/

// Add entry "something 5" but click cancel button (does NOT add entry)
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
Expand All @@ -496,8 +500,8 @@ void TestGui::testAddEntry()

QApplication::processEvents();

// Confirm that 5 entries now exist
QTRY_COMPARE(entryView->model()->rowCount(), 5);
// Confirm entry count
QTRY_COMPARE(entryView->model()->rowCount(), 3);
}

void TestGui::testPasswordEntryEntropy()
Expand Down