diff --git a/src/gui/entry/EditEntryWidget.cpp b/src/gui/entry/EditEntryWidget.cpp index b922f4171..3e26e3092 100644 --- a/src/gui/entry/EditEntryWidget.cpp +++ b/src/gui/entry/EditEntryWidget.cpp @@ -285,7 +285,7 @@ void EditEntryWidget::setupSSHAgent() void EditEntryWidget::updateSSHAgent() { 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->removeKeyFromAgentCheckBox->setChecked(settings.removeAtDatabaseClose()); @@ -299,7 +299,8 @@ void EditEntryWidget::updateSSHAgent() 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") { 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 settings.setSaveAttachmentToTempFile(m_sshAgentSettings.saveAttachmentToTempFile()); - if (settings.isDefault() && m_entryAttachments->hasKey("KeeAgent.settings")) { - m_entryAttachments->remove("KeeAgent.settings"); + if (settings.isDefault()) { + m_advancedUi->attachmentsWidget->removeAttachment("KeeAgent.settings"); } else if (settings != m_sshAgentSettings) { - m_entryAttachments->set("KeeAgent.settings", settings.toXml()); + m_advancedUi->attachmentsWidget->setAttachment("KeeAgent.settings", settings.toXml()); } m_sshAgentSettings = settings; @@ -404,7 +405,7 @@ bool EditEntryWidget::getOpenSSHKey(OpenSSHKey& key) QByteArray privateKeyData; if (m_sshAgentUi->attachmentRadioButton->isChecked()) { - privateKeyData = m_entryAttachments->value(m_sshAgentUi->attachmentComboBox->currentText()); + privateKeyData = m_advancedUi->attachmentsWidget->getAttachment(m_sshAgentUi->attachmentComboBox->currentText()); } else { QFile localFile(m_sshAgentUi->externalFileEdit->text()); diff --git a/src/gui/entry/EntryAttachmentsWidget.cpp b/src/gui/entry/EntryAttachmentsWidget.cpp index 93b73a166..df56e7777 100644 --- a/src/gui/entry/EntryAttachmentsWidget.cpp +++ b/src/gui/entry/EntryAttachmentsWidget.cpp @@ -106,6 +106,23 @@ void EntryAttachmentsWidget::setButtonsVisible(bool 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() { Q_ASSERT(!isReadOnly()); diff --git a/src/gui/entry/EntryAttachmentsWidget.h b/src/gui/entry/EntryAttachmentsWidget.h index 41a54d477..5fd19415e 100644 --- a/src/gui/entry/EntryAttachmentsWidget.h +++ b/src/gui/entry/EntryAttachmentsWidget.h @@ -8,6 +8,7 @@ namespace Ui { class EntryAttachmentsWidget; } +class QByteArray; class EntryAttachments; class EntryAttachmentsModel; @@ -24,6 +25,10 @@ public: bool isReadOnly() const; bool isButtonsVisible() const; + QByteArray getAttachment(const QString& name); + void setAttachment(const QString& name, const QByteArray& value); + void removeAttachment(const QString& name); + public slots: void setEntryAttachments(const EntryAttachments* attachments); void clearAttachments();