mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-08-01 19:16:16 -04:00
Add PDF support in attachment preview dialog
This commit is contained in:
parent
4d7eae34c2
commit
594cb7710c
4 changed files with 17 additions and 3 deletions
|
@ -486,7 +486,9 @@ namespace Tools
|
|||
"application/x-yaml",
|
||||
"application/protobuf",
|
||||
};
|
||||
|
||||
static QStringList imageFormats = {"image/"};
|
||||
static QStringList pdfFormats = {"application/pdf"};
|
||||
|
||||
static auto isCompatible = [](const QString& format, const QStringList& list) {
|
||||
return std::any_of(
|
||||
|
@ -501,6 +503,10 @@ namespace Tools
|
|||
return MimeType::PlainText;
|
||||
}
|
||||
|
||||
if (isCompatible(mimeName, pdfFormats)) {
|
||||
return MimeType::Pdf;
|
||||
}
|
||||
|
||||
return MimeType::Unknown;
|
||||
}
|
||||
} // namespace Tools
|
||||
|
|
|
@ -119,6 +119,7 @@ namespace Tools
|
|||
{
|
||||
Image,
|
||||
PlainText,
|
||||
Pdf,
|
||||
Unknown
|
||||
};
|
||||
|
||||
|
|
|
@ -76,9 +76,17 @@ void PreviewEntryAttachmentsDialog::update()
|
|||
updateImageAttachment(m_data);
|
||||
} else if (m_type == Tools::MimeType::PlainText) {
|
||||
updateTextAttachment(m_data);
|
||||
} else if (m_type == Tools::MimeType::Pdf) {
|
||||
updatePdfAttachment(m_data);
|
||||
}
|
||||
}
|
||||
|
||||
void PreviewEntryAttachmentsDialog::updatePdfAttachment(const QByteArray& data)
|
||||
{
|
||||
// To preview a PDF as an image, you need to install the qt5-image-formats-plugin-pdf
|
||||
updateImageAttachment(data);
|
||||
}
|
||||
|
||||
void PreviewEntryAttachmentsDialog::updateTextAttachment(const QByteArray& data)
|
||||
{
|
||||
m_ui->attachmentTextEdit->setPlainText(QString::fromUtf8(data));
|
||||
|
@ -117,7 +125,5 @@ void PreviewEntryAttachmentsDialog::resizeEvent(QResizeEvent* event)
|
|||
{
|
||||
QDialog::resizeEvent(event);
|
||||
|
||||
if (m_type == Tools::MimeType::Image) {
|
||||
update();
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
|
|
@ -50,6 +50,7 @@ private:
|
|||
void update();
|
||||
void updateTextAttachment(const QByteArray& data);
|
||||
void updateImageAttachment(const QByteArray& data);
|
||||
void updatePdfAttachment(const QByteArray& data);
|
||||
|
||||
QScopedPointer<Ui::EntryAttachmentsDialog> m_ui;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue