Add PDF support in attachment preview dialog

This commit is contained in:
w15dev 2025-01-13 20:31:57 +03:00 committed by Jonathan White
parent 4d7eae34c2
commit 594cb7710c
No known key found for this signature in database
GPG key ID: 440FC65F2E0C6E01
4 changed files with 17 additions and 3 deletions

View file

@ -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

View file

@ -119,6 +119,7 @@ namespace Tools
{
Image,
PlainText,
Pdf,
Unknown
};

View file

@ -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();
}

View file

@ -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;