mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-12-16 08:54:30 -05:00
Support opening attachments directly.
This commit is contained in:
parent
07a3d7a696
commit
c39898dad9
3 changed files with 49 additions and 1 deletions
|
|
@ -25,6 +25,7 @@
|
||||||
#include <QStackedLayout>
|
#include <QStackedLayout>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
|
#include <QTemporaryFile>
|
||||||
|
|
||||||
#include "core/Config.h"
|
#include "core/Config.h"
|
||||||
#include "core/Database.h"
|
#include "core/Database.h"
|
||||||
|
|
@ -107,7 +108,9 @@ void EditEntryWidget::setupAdvanced()
|
||||||
|
|
||||||
m_attachmentsModel->setEntryAttachments(m_entryAttachments);
|
m_attachmentsModel->setEntryAttachments(m_entryAttachments);
|
||||||
m_advancedUi->attachmentsView->setModel(m_attachmentsModel);
|
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->saveAttachmentButton, SIGNAL(clicked()), SLOT(saveCurrentAttachment()));
|
||||||
|
connect(m_advancedUi->openAttachmentButton, SIGNAL(clicked()), SLOT(openCurrentAttachment()));
|
||||||
connect(m_advancedUi->addAttachmentButton, SIGNAL(clicked()), SLOT(insertAttachment()));
|
connect(m_advancedUi->addAttachmentButton, SIGNAL(clicked()), SLOT(insertAttachment()));
|
||||||
connect(m_advancedUi->removeAttachmentButton, SIGNAL(clicked()), SLOT(removeCurrentAttachment()));
|
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()
|
void EditEntryWidget::removeCurrentAttachment()
|
||||||
{
|
{
|
||||||
Q_ASSERT(!m_history);
|
Q_ASSERT(!m_history);
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,8 @@ private Q_SLOTS:
|
||||||
void updateCurrentAttribute();
|
void updateCurrentAttribute();
|
||||||
void insertAttachment();
|
void insertAttachment();
|
||||||
void saveCurrentAttachment();
|
void saveCurrentAttachment();
|
||||||
|
void openAttachment(const QModelIndex& index);
|
||||||
|
void openCurrentAttachment();
|
||||||
void removeCurrentAttachment();
|
void removeCurrentAttachment();
|
||||||
void updateAutoTypeEnabled();
|
void updateAutoTypeEnabled();
|
||||||
void insertAutoTypeAssoc();
|
void insertAutoTypeAssoc();
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>400</width>
|
<width>400</width>
|
||||||
<height>299</height>
|
<height>315</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
|
@ -106,6 +106,13 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="openAttachmentButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Open</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="saveAttachmentButton">
|
<widget class="QPushButton" name="saveAttachmentButton">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue