mirror of https://github.com/vitalif/phantomjs
Create PhantomConfig and migrate output and script encoding settings
parent
c4b1d443ff
commit
a75f7c9dc3
|
@ -49,6 +49,9 @@ Phantom::Phantom(QObject *parent)
|
|||
, m_returnValue(0)
|
||||
, m_netAccessMan(0)
|
||||
{
|
||||
// Load default configuration
|
||||
m_config.load();
|
||||
|
||||
m_page = new WebPage(this);
|
||||
m_pages.append(m_page);
|
||||
|
||||
|
@ -133,11 +136,11 @@ Phantom::Phantom(QObject *parent)
|
|||
continue;
|
||||
}
|
||||
if (arg.startsWith("--output-encoding=")) {
|
||||
Terminal::instance()->setEncoding(arg.mid(18).trimmed());
|
||||
m_config.setOutputEncoding(arg.mid(18).trimmed());
|
||||
continue;
|
||||
}
|
||||
if (arg.startsWith("--script-encoding=")) {
|
||||
m_scriptFileEnc.setEncoding(arg.mid(18).trimmed());
|
||||
m_config.setScriptEncoding(arg.mid(18).trimmed());
|
||||
continue;
|
||||
}
|
||||
if (arg.startsWith("--")) {
|
||||
|
@ -168,6 +171,12 @@ Phantom::Phantom(QObject *parent)
|
|||
m_args += arg;
|
||||
}
|
||||
|
||||
// Set output encoding
|
||||
Terminal::instance()->setEncoding(m_config.outputEncoding());
|
||||
|
||||
// Set script file encoding
|
||||
m_scriptFileEnc.setEncoding(m_config.scriptEncoding());
|
||||
|
||||
// Provide WebPage with a non-standard Network Access Manager
|
||||
m_netAccessMan = new NetworkAccessManager(this, diskCacheEnabled, cookieFile, ignoreSslErrors);
|
||||
m_page->setNetworkAccessManager(m_netAccessMan);
|
||||
|
|
|
@ -38,6 +38,7 @@ class WebPage;
|
|||
#include "networkaccessmanager.h"
|
||||
#include "filesystem.h"
|
||||
#include "encoding.h"
|
||||
#include "phantomconfig.h"
|
||||
|
||||
class Phantom: public QObject
|
||||
{
|
||||
|
@ -89,6 +90,7 @@ private:
|
|||
QVariantMap m_defaultPageSettings;
|
||||
FileSystem m_filesystem;
|
||||
QList<QPointer<WebPage> > m_pages;
|
||||
PhantomConfig m_config;
|
||||
};
|
||||
|
||||
#endif // PHANTOM_H
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
This file is part of the PhantomJS project from Ofi Labs.
|
||||
|
||||
Copyright (C) 2011 Ariya Hidayat <ariya.hidayat@gmail.com>
|
||||
Copyright (C) 2011 execjosh, http://execjosh.blogspot.com
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the <organization> nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "phantomconfig.h"
|
||||
|
||||
// public:
|
||||
PhantomConfig::PhantomConfig()
|
||||
{
|
||||
resetToDefaults();
|
||||
}
|
||||
|
||||
void PhantomConfig::load()
|
||||
{
|
||||
resetToDefaults();
|
||||
}
|
||||
|
||||
QString PhantomConfig::outputEncoding() const
|
||||
{
|
||||
return m_outputEncoding;
|
||||
}
|
||||
|
||||
void PhantomConfig::setOutputEncoding(const QString &value)
|
||||
{
|
||||
if (value.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_outputEncoding = value;
|
||||
}
|
||||
|
||||
QString PhantomConfig::scriptEncoding() const
|
||||
{
|
||||
return m_scriptEncoding;
|
||||
}
|
||||
|
||||
void PhantomConfig::setScriptEncoding(const QString &value)
|
||||
{
|
||||
if (value.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_scriptEncoding = value;
|
||||
}
|
||||
|
||||
// private:
|
||||
void PhantomConfig::resetToDefaults()
|
||||
{
|
||||
m_outputEncoding = "UTF-8";
|
||||
m_scriptEncoding = "UTF-8";
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
This file is part of the PhantomJS project from Ofi Labs.
|
||||
|
||||
Copyright (C) 2011 Ariya Hidayat <ariya.hidayat@gmail.com>
|
||||
Copyright (C) 2011 execjosh, http://execjosh.blogspot.com
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the <organization> nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef PHANTOMCONFIG_H
|
||||
#define PHANTOMCONFIG_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
class PhantomConfig
|
||||
{
|
||||
public:
|
||||
PhantomConfig();
|
||||
|
||||
void load();
|
||||
|
||||
QString outputEncoding() const;
|
||||
void setOutputEncoding(const QString &value);
|
||||
|
||||
QString scriptEncoding() const;
|
||||
void setScriptEncoding(const QString &value);
|
||||
|
||||
private:
|
||||
void resetToDefaults();
|
||||
|
||||
QString m_outputEncoding;
|
||||
QString m_scriptEncoding;
|
||||
};
|
||||
|
||||
#endif // PHANTOMCONFIG_H
|
|
@ -20,7 +20,8 @@ HEADERS += csconverter.h \
|
|||
cookiejar.h \
|
||||
filesystem.h \
|
||||
terminal.h \
|
||||
encoding.h
|
||||
encoding.h \
|
||||
phantomconfig.h
|
||||
SOURCES += phantom.cpp \
|
||||
webpage.cpp \
|
||||
main.cpp \
|
||||
|
@ -31,7 +32,8 @@ SOURCES += phantom.cpp \
|
|||
cookiejar.cpp \
|
||||
filesystem.cpp \
|
||||
terminal.cpp \
|
||||
encoding.cpp
|
||||
encoding.cpp \
|
||||
phantomconfig.cpp
|
||||
|
||||
OTHER_FILES = bootstrap.js usage.txt
|
||||
|
||||
|
|
Loading…
Reference in New Issue