mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-01-26 22:36:59 -05:00
Support opening attachments directly.
This commit is contained in:
parent
07a3d7a696
commit
c39898dad9
@ -25,6 +25,7 @@
|
||||
#include <QStackedLayout>
|
||||
#include <QMenu>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QTemporaryFile>
|
||||
|
||||
#include "core/Config.h"
|
||||
#include "core/Database.h"
|
||||
@ -107,7 +108,9 @@ void EditEntryWidget::setupAdvanced()
|
||||
|
||||
m_attachmentsModel->setEntryAttachments(m_entryAttachments);
|
||||
m_advancedUi->attachmentsView->setModel(m_attachmentsModel);
|
||||
connect(m_advancedUi->attachmentsView, SIGNAL(doubleClicked(QModelIndex)), SLOT(openAttachment(QModelIndex)));
|
||||
connect(m_advancedUi->saveAttachmentButton, SIGNAL(clicked()), SLOT(saveCurrentAttachment()));
|
||||
connect(m_advancedUi->openAttachmentButton, SIGNAL(clicked()), SLOT(openCurrentAttachment()));
|
||||
connect(m_advancedUi->addAttachmentButton, SIGNAL(clicked()), SLOT(insertAttachment()));
|
||||
connect(m_advancedUi->removeAttachmentButton, SIGNAL(clicked()), SLOT(removeCurrentAttachment()));
|
||||
|
||||
@ -636,6 +639,42 @@ void EditEntryWidget::saveCurrentAttachment()
|
||||
}
|
||||
}
|
||||
|
||||
void EditEntryWidget::openAttachment(const QModelIndex& index)
|
||||
{
|
||||
if (!index.isValid()) {
|
||||
Q_ASSERT(false);
|
||||
return;
|
||||
}
|
||||
|
||||
QString filename = m_attachmentsModel->keyByIndex(index);
|
||||
QByteArray attachmentData = m_entryAttachments->value(filename);
|
||||
|
||||
// tmp file will be removed once the database (or the application) has been closed
|
||||
QString tmpFileTemplate = QDir::temp().absoluteFilePath(filename);
|
||||
QTemporaryFile* file = new QTemporaryFile(tmpFileTemplate, this);
|
||||
|
||||
if (!file->open()) {
|
||||
MessageBox::warning(this, tr("Error"),
|
||||
tr("Unable to save the attachment:\n").append(file->errorString()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (file->write(attachmentData) != attachmentData.size()) {
|
||||
MessageBox::warning(this, tr("Error"),
|
||||
tr("Unable to save the attachment:\n").append(file->errorString()));
|
||||
return;
|
||||
}
|
||||
|
||||
QDesktopServices::openUrl(QUrl::fromLocalFile(file->fileName()));
|
||||
}
|
||||
|
||||
void EditEntryWidget::openCurrentAttachment()
|
||||
{
|
||||
QModelIndex index = m_advancedUi->attachmentsView->currentIndex();
|
||||
|
||||
openAttachment(index);
|
||||
}
|
||||
|
||||
void EditEntryWidget::removeCurrentAttachment()
|
||||
{
|
||||
Q_ASSERT(!m_history);
|
||||
|
@ -76,6 +76,8 @@ private Q_SLOTS:
|
||||
void updateCurrentAttribute();
|
||||
void insertAttachment();
|
||||
void saveCurrentAttachment();
|
||||
void openAttachment(const QModelIndex& index);
|
||||
void openCurrentAttachment();
|
||||
void removeCurrentAttachment();
|
||||
void updateAutoTypeEnabled();
|
||||
void insertAutoTypeAssoc();
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>299</height>
|
||||
<height>315</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
@ -106,6 +106,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="openAttachmentButton">
|
||||
<property name="text">
|
||||
<string>Open</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="saveAttachmentButton">
|
||||
<property name="text">
|
||||
|
Loading…
x
Reference in New Issue
Block a user