Messagelib

webengineexportpdfpagejob.cpp
1 /*
2  SPDX-FileCopyrightText: 2020-2023 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "webengineexportpdfpagejob.h"
8 #include "webengineviewer_debug.h"
9 #include <QWebEngineView>
10 
11 using namespace WebEngineViewer;
12 WebEngineExportPdfPageJob::WebEngineExportPdfPageJob(QObject *parent)
13  : QObject(parent)
14 {
15 }
16 
17 WebEngineExportPdfPageJob::~WebEngineExportPdfPageJob() = default;
18 
19 void WebEngineExportPdfPageJob::start()
20 {
21  if (!canStart()) {
22  qCWarning(WEBENGINEVIEWER_LOG) << "webengineview not defined or path is not defined.! It's a bug";
23  Q_EMIT exportPdfFailed();
24  deleteLater();
25  return;
26  }
27  connect(mWebEngineView->page(), &QWebEnginePage::pdfPrintingFinished, this, &WebEngineExportPdfPageJob::slotPdfPrintingFinished);
28  mWebEngineView->page()->printToPdf(mPdfPath);
29 }
30 
31 void WebEngineExportPdfPageJob::slotPdfPrintingFinished(const QString &filePath, bool success)
32 {
33  if (success) {
34  Q_EMIT exportToPdfSuccess();
35  } else {
36  qCWarning(WEBENGINEVIEWER_LOG) << "Failed to export to pdf to " << filePath;
37  Q_EMIT exportPdfFailed();
38  }
39  deleteLater();
40 }
41 
42 QWebEngineView *WebEngineExportPdfPageJob::engineView() const
43 {
44  return mWebEngineView;
45 }
46 
47 void WebEngineExportPdfPageJob::setEngineView(QWebEngineView *engineView)
48 {
49  mWebEngineView = engineView;
50 }
51 
52 QString WebEngineExportPdfPageJob::pdfPath() const
53 {
54  return mPdfPath;
55 }
56 
57 void WebEngineExportPdfPageJob::setPdfPath(const QString &pdfPath)
58 {
59  mPdfPath = pdfPath;
60 }
61 
62 bool WebEngineExportPdfPageJob::canStart() const
63 {
64  return mWebEngineView && !mPdfPath.isEmpty();
65 }
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void deleteLater()
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Fri Mar 24 2023 04:08:32 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.