summaryrefslogtreecommitdiff
path: root/www-client/falkon/files/falkon-24.08.3-fix-printing.patch
blob: 8e5aecd366d8012741ae2afe1a38cd16b72c669e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
From cbf47b0625c9b67b3608e24600273693bd59462a Mon Sep 17 00:00:00 2001
From: Juraj Oravec <jurajoravec@mailo.com>
Date: Wed, 4 Dec 2024 21:34:31 +0100
Subject: [PATCH] Fix printing to printer other than PDF printer

BUG: 497051
FIXED-IN: 24.12

Chery picked from: eaa807023517e1d62dae41f9b1cdd93806d77d64

Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
---
 src/lib/webengine/webview.cpp | 22 ++++++++++++++--------
 src/lib/webengine/webview.h   |  4 ++++
 2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/src/lib/webengine/webview.cpp b/src/lib/webengine/webview.cpp
index d2b5d7ee0..4871e8b3f 100644
--- a/src/lib/webengine/webview.cpp
+++ b/src/lib/webengine/webview.cpp
@@ -67,6 +67,7 @@ WebView::WebView(QWidget* parent)
     connect(this, &QWebEngineView::iconChanged, this, &WebView::slotIconChanged);
     connect(this, &QWebEngineView::urlChanged, this, &WebView::slotUrlChanged);
     connect(this, &QWebEngineView::titleChanged, this, &WebView::slotTitleChanged);
+    connect(this, &QWebEngineView::printFinished, this, &WebView::slotPrintFinished);
 
     m_currentZoomLevel = zoomLevels().indexOf(100);
 
@@ -386,11 +387,11 @@ void WebView::printPage()
 {
     Q_ASSERT(m_page);
 
-    auto *printer = new QPrinter();
-    printer->setCreator(tr("Falkon %1 (%2)").arg(QString::fromLatin1(Qz::VERSION), QString::fromLatin1(Qz::WWWADDRESS)));
-    printer->setDocName(QzTools::filterCharsFromFilename(title()));
+    m_printer = new QPrinter();
+    m_printer->setCreator(tr("Falkon %1 (%2)").arg(QString::fromLatin1(Qz::VERSION), QString::fromLatin1(Qz::WWWADDRESS)));
+    m_printer->setDocName(QzTools::filterCharsFromFilename(title()));
 
-    auto *dialog = new QPrintDialog(printer, this);
+    auto *dialog = new QPrintDialog(m_printer, this);
     dialog->setOptions(QAbstractPrintDialog::PrintToFile | QAbstractPrintDialog::PrintShowPageSize);
 #ifndef Q_OS_WIN
     dialog->setOption(QAbstractPrintDialog::PrintPageRange);
@@ -402,14 +403,19 @@ void WebView::printPage()
             m_page->printToPdf(dialog->printer()->outputFileName(), dialog->printer()->pageLayout());
             delete dialog;
         } else {
-            connect(this, &QWebEngineView::printFinished, this, [&dialog](bool success) {
-                Q_UNUSED(success);
-                delete dialog;
-            });
+            print(m_printer);
+            delete dialog;
         }
     }
 }
 
+void WebView::slotPrintFinished(bool success)
+{
+    Q_UNUSED(success);
+    delete m_printer;
+    m_printer = nullptr;
+}
+
 void WebView::slotLoadStarted()
 {
     m_progress = 0;
diff --git a/src/lib/webengine/webview.h b/src/lib/webengine/webview.h
index 37138cd6d..61e7281f8 100644
--- a/src/lib/webengine/webview.h
+++ b/src/lib/webengine/webview.h
@@ -25,6 +25,7 @@
 #include "loadrequest.h"
 #include "wheelhelper.h"
 
+class QPrinter;
 class WebPage;
 class LoadRequest;
 class WebHitTestResult;
@@ -118,6 +119,7 @@ protected Q_SLOTS:
     void slotIconChanged();
     void slotUrlChanged(const QUrl &url);
     void slotTitleChanged(const QString &title);
+    void slotPrintFinished(bool success);
 
     // Context menu slots
     void openUrlInNewWindow();
@@ -193,6 +195,8 @@ private:
     WheelHelper m_wheelHelper;
 
     static bool s_forceContextMenuOnMouseRelease;
+
+    QPrinter* m_printer;
 };
 
 #endif // WEBVIEW_H
-- 
GitLab