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

Minor fixes for 2.4.1 #2947

Merged
merged 4 commits into from
Apr 7, 2019
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
3 changes: 2 additions & 1 deletion src/format/Kdbx3Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ bool Kdbx3Reader::readDatabaseImpl(QIODevice* device,
QByteArray realStart = cipherStream.read(32);

if (realStart != m_streamStartBytes) {
raiseError(tr("Wrong key or database file is corrupt."));
raiseError(tr("Invalid credentials were provided, please try again.\n"
"If this reoccurs, then your database file may be corrupt."));
return false;
}

Expand Down
3 changes: 2 additions & 1 deletion src/format/Kdbx4Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ bool Kdbx4Reader::readDatabaseImpl(QIODevice* device,
// clang-format off
QByteArray hmacKey = KeePass2::hmacKey(m_masterSeed, db->transformedMasterKey());
if (headerHmac != CryptoHash::hmac(headerData, HmacBlockStream::getHmacKey(UINT64_MAX, hmacKey), CryptoHash::Sha256)) {
raiseError(tr("Wrong key or database file is corrupt. (HMAC mismatch)"));
raiseError(tr("Invalid credentials were provided, please try again.\n"
"If this reoccurs, then your database file may be corrupt.") + " " + tr("(HMAC mismatch)"));
return false;
}
HmacBlockStream hmacStream(device, hmacKey);
Expand Down
3 changes: 2 additions & 1 deletion src/format/KeePass1Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,8 @@ KeePass1Reader::testKeys(const QString& password, const QByteArray& keyfileData,
}

if (!cipherStream) {
raiseError(tr("Wrong key or database file is corrupt."));
raiseError(tr("Invalid credentials were provided, please try again.\n"
"If this reoccurs, then your database file may be corrupt."));
}

return cipherStream.take();
Expand Down
9 changes: 8 additions & 1 deletion src/gui/ApplicationSettingsWidgetGeneral.ui
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@
<item alignment="Qt::AlignRight">
<widget class="QLabel" name="languageLabel_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
Expand All @@ -490,6 +490,13 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="languageLabel_3">
<property name="text">
<string>(restart program to activate)</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
Expand Down
7 changes: 3 additions & 4 deletions src/gui/DatabaseOpenWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ void DatabaseOpenWidget::openDatabase()
bool ok = m_db->open(m_filename, masterKey, &error, false);
QApplication::restoreOverrideCursor();
if (!ok) {
m_ui->messageWidget->showMessage(tr("Unable to open the database:\n%1").arg(error),
MessageWidget::MessageType::Error);
m_ui->messageWidget->showMessage(error, MessageWidget::MessageType::Error);
return;
}

Expand Down Expand Up @@ -223,7 +222,7 @@ void DatabaseOpenWidget::openDatabase()
}
emit dialogFinished(true);
} else {
m_ui->messageWidget->showMessage(tr("Unable to open the database:\n%1").arg(error), MessageWidget::Error);
m_ui->messageWidget->showMessage(error, MessageWidget::Error);
m_ui->editPassword->setText("");

#ifdef WITH_XC_TOUCHID
Expand Down Expand Up @@ -268,7 +267,7 @@ QSharedPointer<CompositeKey> DatabaseOpenWidget::databaseKey()
QString keyFilename = m_ui->comboKeyFile->currentText();
QString errorMsg;
if (!key->load(keyFilename, &errorMsg)) {
m_ui->messageWidget->showMessage(tr("Can't open key file:\n%1").arg(errorMsg), MessageWidget::Error);
m_ui->messageWidget->showMessage(tr("Failed to open key file: %1").arg(errorMsg), MessageWidget::Error);
return {};
}
if (key->type() != FileKey::Hashed && !config()->get("Messages/NoLegacyKeyFileWarning").toBool()) {
Expand Down
11 changes: 5 additions & 6 deletions src/gui/DatabaseWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,11 @@ bool DatabaseWidget::isSearchActive() const
bool DatabaseWidget::isEditWidgetModified() const
{
if (currentWidget() == m_editEntryWidget) {
return m_editEntryWidget->hasBeenModified();
} else {
// other edit widget don't have a hasBeenModified() method yet
// assume that they already have been modified
return true;
return m_editEntryWidget->isModified();
} else if (currentWidget() == m_editGroupWidget) {
return m_editGroupWidget->isModified();
}
return false;
}

QList<int> DatabaseWidget::mainSplitterSizes() const
Expand Down Expand Up @@ -1247,7 +1246,7 @@ bool DatabaseWidget::lock()

clipboard()->clearCopiedText();

if (currentMode() == DatabaseWidget::Mode::EditMode) {
if (isEditWidgetModified()) {
auto result = MessageBox::question(this,
tr("Lock Database?"),
tr("You are editing an entry. Discard changes and lock anyway?"),
Expand Down
37 changes: 34 additions & 3 deletions src/gui/EditWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ EditWidget::EditWidget(QWidget* parent)
{
m_ui->setupUi(this);
setReadOnly(false);
setModified(false);

m_ui->messageWidget->setHidden(true);

Expand All @@ -43,6 +44,7 @@ EditWidget::EditWidget(QWidget* parent)

connect(m_ui->buttonBox, SIGNAL(accepted()), SIGNAL(accepted()));
connect(m_ui->buttonBox, SIGNAL(rejected()), SIGNAL(rejected()));
connect(m_ui->buttonBox, SIGNAL(clicked(QAbstractButton*)), SLOT(buttonClicked(QAbstractButton*)));
}

EditWidget::~EditWidget()
Expand Down Expand Up @@ -106,9 +108,6 @@ void EditWidget::setReadOnly(bool 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()));
}
}

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

void EditWidget::setModified(bool state)
{
m_modified = state;
enableApplyButton(state);
}

bool EditWidget::isModified() const
{
return m_modified;
}

void EditWidget::enableApplyButton(bool enabled)
{
QPushButton* applyButton = m_ui->buttonBox->button(QDialogButtonBox::Apply);
Expand All @@ -125,6 +135,27 @@ void EditWidget::enableApplyButton(bool enabled)
}
}

void EditWidget::showApplyButton(bool state)
{
if (!m_readOnly) {
auto buttons = m_ui->buttonBox->standardButtons();
if (state) {
buttons |= QDialogButtonBox::Apply;
} else {
buttons &= ~QDialogButtonBox::Apply;
}
m_ui->buttonBox->setStandardButtons(buttons);
}
}

void EditWidget::buttonClicked(QAbstractButton* button)
{
auto stdButton = m_ui->buttonBox->standardButton(button);
if (stdButton == QDialogButtonBox::Apply) {
emit apply();
}
}

void EditWidget::showMessage(const QString& text, MessageWidget::MessageType type)
{
// Show error messages for a longer time to make sure the user can read them
Expand Down
5 changes: 5 additions & 0 deletions src/gui/EditWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class EditWidget : public DialogyWidget
void setReadOnly(bool readOnly);
bool readOnly() const;
void enableApplyButton(bool enabled);
void showApplyButton(bool state);
virtual bool isModified() const;

signals:
void apply();
Expand All @@ -58,10 +60,13 @@ class EditWidget : public DialogyWidget
protected slots:
void showMessage(const QString& text, MessageWidget::MessageType type);
void hideMessage();
void setModified(bool state = true);
void buttonClicked(QAbstractButton* button);

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

Q_DISABLE_COPY(EditWidget)
};
Expand Down
8 changes: 7 additions & 1 deletion src/gui/SearchWidget.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*
* Copyright (C) 2016 Jonathan White <support@dmapps.us>
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -97,6 +96,13 @@ bool SearchWidget::eventFilter(QObject* obj, QEvent* event)
if (keyEvent->key() == Qt::Key_Escape) {
emit escapePressed();
return true;
} else if (keyEvent->matches(QKeySequence::Copy)) {
// If Control+C is pressed in the search edit when no text
// is selected, copy the password of the current entry.
if (!m_ui->searchEdit->hasSelectedText()) {
emit copyPressed();
return true;
}
} else if (keyEvent->matches(QKeySequence::MoveToNextLine)) {
if (m_ui->searchEdit->cursorPosition() == m_ui->searchEdit->text().length()) {
// If down is pressed at EOL, move the focus to the entry view
Expand Down
Loading