Correct regression to ssh-agent from entry attachment refactor

This commit is contained in:
Jonathan White 2017-12-25 11:07:02 -05:00 committed by Janek Bevendorff
parent 497eb3c587
commit cc1ab94a4f
3 changed files with 29 additions and 6 deletions

View File

@ -285,7 +285,7 @@ void EditEntryWidget::setupSSHAgent()
void EditEntryWidget::updateSSHAgent() void EditEntryWidget::updateSSHAgent()
{ {
KeeAgentSettings settings; KeeAgentSettings settings;
settings.fromXml(m_entryAttachments->value("KeeAgent.settings")); settings.fromXml(m_advancedUi->attachmentsWidget->getAttachment("KeeAgent.settings"));
m_sshAgentUi->addKeyToAgentCheckBox->setChecked(settings.addAtDatabaseOpen()); m_sshAgentUi->addKeyToAgentCheckBox->setChecked(settings.addAtDatabaseOpen());
m_sshAgentUi->removeKeyFromAgentCheckBox->setChecked(settings.removeAtDatabaseClose()); m_sshAgentUi->removeKeyFromAgentCheckBox->setChecked(settings.removeAtDatabaseClose());
@ -299,7 +299,8 @@ void EditEntryWidget::updateSSHAgent()
m_sshAgentUi->attachmentComboBox->addItem(""); m_sshAgentUi->attachmentComboBox->addItem("");
for (QString fileName : m_entryAttachments->keys()) { auto attachments = m_advancedUi->attachmentsWidget->entryAttachments();
for (const QString& fileName : attachments->keys()) {
if (fileName == "KeeAgent.settings") { if (fileName == "KeeAgent.settings") {
continue; continue;
} }
@ -382,10 +383,10 @@ void EditEntryWidget::saveSSHAgentConfig()
// we don't use this either but we don't want it to dirty flag the config // we don't use this either but we don't want it to dirty flag the config
settings.setSaveAttachmentToTempFile(m_sshAgentSettings.saveAttachmentToTempFile()); settings.setSaveAttachmentToTempFile(m_sshAgentSettings.saveAttachmentToTempFile());
if (settings.isDefault() && m_entryAttachments->hasKey("KeeAgent.settings")) { if (settings.isDefault()) {
m_entryAttachments->remove("KeeAgent.settings"); m_advancedUi->attachmentsWidget->removeAttachment("KeeAgent.settings");
} else if (settings != m_sshAgentSettings) { } else if (settings != m_sshAgentSettings) {
m_entryAttachments->set("KeeAgent.settings", settings.toXml()); m_advancedUi->attachmentsWidget->setAttachment("KeeAgent.settings", settings.toXml());
} }
m_sshAgentSettings = settings; m_sshAgentSettings = settings;
@ -404,7 +405,7 @@ bool EditEntryWidget::getOpenSSHKey(OpenSSHKey& key)
QByteArray privateKeyData; QByteArray privateKeyData;
if (m_sshAgentUi->attachmentRadioButton->isChecked()) { if (m_sshAgentUi->attachmentRadioButton->isChecked()) {
privateKeyData = m_entryAttachments->value(m_sshAgentUi->attachmentComboBox->currentText()); privateKeyData = m_advancedUi->attachmentsWidget->getAttachment(m_sshAgentUi->attachmentComboBox->currentText());
} else { } else {
QFile localFile(m_sshAgentUi->externalFileEdit->text()); QFile localFile(m_sshAgentUi->externalFileEdit->text());

View File

@ -106,6 +106,23 @@ void EntryAttachmentsWidget::setButtonsVisible(bool buttonsVisible)
emit buttonsVisibleChanged(m_buttonsVisible); emit buttonsVisibleChanged(m_buttonsVisible);
} }
QByteArray EntryAttachmentsWidget::getAttachment(const QString &name)
{
return m_entryAttachments->value(name);
}
void EntryAttachmentsWidget::setAttachment(const QString &name, const QByteArray &value)
{
m_entryAttachments->set(name, value);
}
void EntryAttachmentsWidget::removeAttachment(const QString &name)
{
if (!isReadOnly() && m_entryAttachments->hasKey(name)) {
m_entryAttachments->remove(name);
}
}
void EntryAttachmentsWidget::insertAttachments() void EntryAttachmentsWidget::insertAttachments()
{ {
Q_ASSERT(!isReadOnly()); Q_ASSERT(!isReadOnly());

View File

@ -8,6 +8,7 @@ namespace Ui {
class EntryAttachmentsWidget; class EntryAttachmentsWidget;
} }
class QByteArray;
class EntryAttachments; class EntryAttachments;
class EntryAttachmentsModel; class EntryAttachmentsModel;
@ -24,6 +25,10 @@ public:
bool isReadOnly() const; bool isReadOnly() const;
bool isButtonsVisible() const; bool isButtonsVisible() const;
QByteArray getAttachment(const QString& name);
void setAttachment(const QString& name, const QByteArray& value);
void removeAttachment(const QString& name);
public slots: public slots:
void setEntryAttachments(const EntryAttachments* attachments); void setEntryAttachments(const EntryAttachments* attachments);
void clearAttachments(); void clearAttachments();