source: wkhtmltox/trunk/fuentes/src/lib/converter.cc @ 51

Last change on this file since 51 was 51, checked in by mabarracus, 4 years ago

wip

File size: 4.7 KB
Line 
1// -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*-
2// vi:set ts=4 sts=4 sw=4 noet :
3//
4// Copyright 2010 wkhtmltopdf authors
5//
6// This file is part of wkhtmltopdf.
7//
8// wkhtmltopdf is free software: you can redistribute it and/or modify
9// it under the terms of the GNU Lesser General Public License as published by
10// the Free Software Foundation, either version 3 of the License, or
11// (at your option) any later version.
12//
13// wkhtmltopdf is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16// GNU General Public License for more details.
17//
18// You should have received a copy of the GNU Lesser General Public License
19// along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
20
21
22#include "converter_p.hh"
23#include "multipageloader.hh"
24#include <QWebFrame>
25#include <qapplication.h>
26
27#ifdef QT4_STATICPLUGIN_TEXTCODECS
28#include <QtPlugin>
29Q_IMPORT_PLUGIN(qcncodecs)
30Q_IMPORT_PLUGIN(qjpcodecs)
31Q_IMPORT_PLUGIN(qkrcodecs)
32Q_IMPORT_PLUGIN(qtwcodecs)
33#endif
34
35namespace wkhtmltopdf {
36
37
38void ConverterPrivate::updateWebSettings(QWebSettings * ws, const settings::Web & s) const {
39#ifdef  __EXTENSIVE_WKHTMLTOPDF_QT_HACK__
40        if (!s.defaultEncoding.isEmpty())
41                ws->setDefaultTextEncoding(s.defaultEncoding);
42        if (!s.enableIntelligentShrinking) {
43                ws->setPrintingMaximumShrinkFactor(1.0);
44                ws->setPrintingMinimumShrinkFactor(1.0);
45        }
46        ws->setPrintingMediaType(s.printMediaType?"print":"screen");
47#endif
48        ws->setAttribute(QWebSettings::JavaEnabled, s.enablePlugins);
49        ws->setAttribute(QWebSettings::JavascriptEnabled, s.enableJavascript);
50        ws->setAttribute(QWebSettings::JavascriptCanOpenWindows, false);
51        ws->setAttribute(QWebSettings::JavascriptCanAccessClipboard, false);
52        ws->setFontSize(QWebSettings::MinimumFontSize, s.minimumFontSize);
53        //Newer versions of QT have even more settings to change
54        ws->setAttribute(QWebSettings::PrintElementBackgrounds, s.background);
55        ws->setAttribute(QWebSettings::AutoLoadImages, s.loadImages);
56        ws->setAttribute(QWebSettings::PluginsEnabled, s.enablePlugins);
57        if (!s.userStyleSheet.isEmpty())
58                ws->setUserStyleSheetUrl(MultiPageLoader::guessUrlFromString(s.userStyleSheet));
59}
60
61void ConverterPrivate::fail() {
62        error = true;
63        convertionDone = true;
64        clearResources();
65        emit outer().finished(false);
66        qApp->exit(0); // quit qt's event handling
67}
68
69/*!
70 * Called when the page is loading, display some progress to the using
71 * \param progress the loading progress in percent
72 */
73void ConverterPrivate::loadProgress(int progress) {
74        progressString = QString::number(progress) + "%";
75        emit outer().progressChanged(progress);
76}
77
78void ConverterPrivate::forwardError(QString error) {
79        emit outer().error(error);
80}
81
82void ConverterPrivate::forwardWarning(QString warning) {
83        emit outer().warning(warning);
84}
85
86void ConverterPrivate::cancel() {
87        error=true;
88}
89
90bool ConverterPrivate::convert() {
91        convertionDone=false;
92        beginConvert();
93        while (!convertionDone)
94                qApp->processEvents(QEventLoop::WaitForMoreEvents | QEventLoop::AllEvents);
95        return !error;
96}
97
98
99/*!
100  \brief Count the number of phases that the conversion process goes though
101*/
102int Converter::phaseCount() {
103        return priv().phaseDescriptions.size();
104}
105
106/*!
107  \brief return the current phase of conversion
108*/
109int Converter::currentPhase() {
110        return priv().currentPhase;
111}
112
113/*!
114  \brief return a textual description of some phase
115  \param phase the phase to get a description of, -1 for current phase
116*/
117QString Converter::phaseDescription(int phase) {
118        if (phase < 0 || priv().phaseDescriptions.size() <= phase) phase=priv().currentPhase;
119        if (phase < 0 || priv().phaseDescriptions.size() <= phase) return "Invalid";
120        return priv().phaseDescriptions[phase];
121}
122
123/*!
124  \brief return a textual description of progress in the current phase
125*/
126QString Converter::progressString() {
127        return priv().progressString;
128}
129
130/*!
131  \brief return the HTTP return code, of the converted page
132*/
133int Converter::httpErrorCode() {
134        return priv().errorCode;
135}
136
137/*!
138  \brief Start a asynchronous conversion of html pages to a pdf document.
139  Once conversion is done an finished signal will be emitted
140*/
141void Converter::beginConvertion() {
142        priv().beginConvert();
143}
144
145/*!
146  \brief Synchronous convert html pages to a pdf document.
147*/
148bool Converter::convert() {
149        return priv().convert();
150}
151
152/*!
153  \brief Cancel a running conversion
154*/
155void Converter::cancel() {
156        priv().cancel();
157}
158
159void Converter::emitCheckboxSvgs(const settings::LoadPage & ls) {
160        emit checkboxSvgChanged(ls.checkboxSvg);
161        emit checkboxCheckedSvgChanged(ls.checkboxCheckedSvg);
162        emit radiobuttonSvgChanged(ls.radiobuttonSvg);
163        emit radiobuttonCheckedSvgChanged(ls.radiobuttonCheckedSvg);
164}
165
166}
Note: See TracBrowser for help on using the repository browser.