[graphics/okular] /: Notify the user about possible changes at printing
Sune Vuorela <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit 93f89f972b29a6490eb011b8ab75381a3f8c06fe by Sune Vuorela.
Committed on 07/08/2026 at 12:30.
Pushed by sune into branch 'master'.
Notify the user about possible changes at printing
Under various conditions, the document might be printed with different
elements than what's shown on screen.
This is not always a hostile thing, but it can be.
This is part of the pdf specification, and it has plenty of 'good uses',
though it can also be used for bad. We have no knowledge of if it is bad
or god, so alert the user.
M +24 -0 core/document.cpp
M +6 -0 core/document.h
M +9 -0 core/scripter.cpp
M +2 -0 core/scripter.h
M +28 -0 part/part.cpp
M +1 -0 part/part.h
https://invent.kde.org/graphics/okular/-/commit/93f89f972b29a6490eb011b8ab75381a3f8c06fe
diff --git a/core/document.cpp b/core/document.cpp
index 771d14f44..b9868aaca 100644
--- a/core/document.cpp
+++ b/core/document.cpp
@@ -4559,6 +4559,30 @@ void Document::processKVCFActions(Okular::FormField *ff)
}
}
+QList<Document::DocumentAdditionalActionType> Document::documentAdditionalActionTypes() const
+{
+ QList<DocumentAdditionalActionType> types;
+ if (!Scripter::canExecuteScripts()) {
+ return types;
+ }
+ if (d->m_generator->additionalDocumentAction(Document::CloseDocument)) {
+ types << Document::CloseDocument;
+ }
+ if (d->m_generator->additionalDocumentAction(Document::PrintDocumentStart)) {
+ types << Document::PrintDocumentStart;
+ }
+ if (d->m_generator->additionalDocumentAction(Document::PrintDocumentFinish)) {
+ types << Document::PrintDocumentFinish;
+ }
+ if (d->m_generator->additionalDocumentAction(Document::SaveDocumentStart)) {
+ types << Document::SaveDocumentFinish;
+ }
+ if (d->m_generator->additionalDocumentAction(Document::SaveDocumentFinish)) {
+ types << Document::SaveDocumentFinish;
+ }
+ return types;
+}
+
void Document::processDocumentAction(const Action *action, DocumentAdditionalActionType type)
{
if (!action || action->actionType() != Action::Script) {
diff --git a/core/document.h b/core/document.h
index 10ed8b9f3..0b458424f 100644
--- a/core/document.h
+++ b/core/document.h
@@ -788,6 +788,12 @@ public:
*/
void processDocumentAction(const Action *action, DocumentAdditionalActionType type);
+ /**
+ * Returns the list of documentAdditionalActionType available for this document
+ * @since 26.08
+ */
+ QList<DocumentAdditionalActionType> documentAdditionalActionTypes() const;
+
/**
* Recalculates all the form fields in the document
*
diff --git a/core/scripter.cpp b/core/scripter.cpp
index 221ff3753..3ca3276e8 100644
--- a/core/scripter.cpp
+++ b/core/scripter.cpp
@@ -59,6 +59,15 @@ Scripter::~Scripter()
delete d;
}
+bool Scripter::canExecuteScripts()
+{
+#if HAVE_JS
+ return true;
+#else
+ return false;
+#endif
+}
+
void Scripter::execute(Event *event, ScriptType type, const QString &script)
{
qCDebug(OkularCoreDebug) << "executing the script:" << script;
diff --git a/core/scripter.h b/core/scripter.h
index a756aa2f2..8a0b5cc6e 100644
--- a/core/scripter.h
+++ b/core/scripter.h
@@ -31,6 +31,8 @@ public:
void execute(Event *event, ScriptType type, const QString &script);
+ static bool canExecuteScripts();
+
private:
friend class ScripterPrivate;
ScripterPrivate *d;
diff --git a/part/part.cpp b/part/part.cpp
index 423934d7c..f354c5e5b 100644
--- a/part/part.cpp
+++ b/part/part.cpp
@@ -460,6 +460,13 @@ Part::Part(QObject *parent, const QVariantList &args)
m_infoTimer = new QTimer();
m_infoTimer->setSingleShot(true);
connect(m_infoTimer, &QTimer::timeout, m_infoMessage, &KMessageWidget::animatedHide);
+ m_printMightDifferMessage = new KMessageWidget(rightContainer);
+ m_printMightDifferMessage->setVisible(false);
+ m_printMightDifferMessage->setWordWrap(true);
+ m_printMightDifferMessage->setPosition(KMessageWidget::Position::Header);
+ m_printMightDifferMessage->setText(
+ i18nc("This is a normal pdf feature, but can be abused by hostile parties", "This document has elements that might be hidden or shown differently when printed. For important documents, please verify both."));
+ rightLayout->addWidget(m_printMightDifferMessage);
m_signatureMessage = new KMessageWidget(rightContainer);
m_signatureMessage->setVisible(false);
m_signatureMessage->setWordWrap(true);
@@ -1633,6 +1640,27 @@ bool Part::openFile()
}
}
}
+
+ m_printMightDifferMessage->setVisible(false);
+
+ QList<Document::DocumentAdditionalActionType> actionTypes = m_document->documentAdditionalActionTypes();
+ if (actionTypes.contains(Document::PrintDocumentStart) || actionTypes.contains(Document::PrintDocumentFinish)) {
+ m_printMightDifferMessage->setVisible(true);
+ }
+
+ for (uint i = 0; (i < m_document->pages()) && m_printMightDifferMessage->isHidden(); i++) {
+ const auto pageAnnots = m_document->page(i)->annotations();
+ for (auto *annot : pageAnnots) {
+ if (annot->flags() & Okular::Annotation::DenyPrint && !(annot->flags() & Okular::Annotation::Hidden)) {
+ m_printMightDifferMessage->setVisible(true);
+ break;
+ }
+ if (!(annot->flags() & Okular::Annotation::DenyPrint) && (annot->flags() & Okular::Annotation::Hidden)) {
+ m_printMightDifferMessage->setVisible(true);
+ break;
+ }
+ }
+ }
}
if (m_showPresentation) {
diff --git a/part/part.h b/part/part.h
index 7fc39c678..e4b4983fa 100644
--- a/part/part.h
+++ b/part/part.h
@@ -365,6 +365,7 @@ private:
KMessageWidget *m_migrationMessage;
KMessageWidget *m_topMessage;
KMessageWidget *m_formsMessage;
+ KMessageWidget *m_printMightDifferMessage;
KMessageWidget *m_infoMessage;
KMessageWidget *m_signatureMessage;
#if HAVE_NEW_SIGNATURE_API