From a445b2d7b9e10379c9679885988f9ad30ce365b1 Mon Sep 17 00:00:00 2001 From: execjosh Date: Sat, 27 Aug 2011 03:02:51 +0900 Subject: [PATCH] Migrate network access manager settings to PhantomConfig --- src/phantom.cpp | 15 ++++++--------- src/phantomconfig.cpp | 33 +++++++++++++++++++++++++++++++++ src/phantomconfig.h | 12 ++++++++++++ 3 files changed, 51 insertions(+), 9 deletions(-) diff --git a/src/phantom.cpp b/src/phantom.cpp index dd5a5fc3..a069cef3 100644 --- a/src/phantom.cpp +++ b/src/phantom.cpp @@ -55,11 +55,8 @@ Phantom::Phantom(QObject *parent) m_page = new WebPage(this); m_pages.append(m_page); - QString cookieFile; bool autoLoadImages = true; bool pluginsEnabled = false; - bool diskCacheEnabled = false; - bool ignoreSslErrors = false; bool localAccessRemote = false; // second argument: script name @@ -94,19 +91,19 @@ Phantom::Phantom(QObject *parent) continue; } if (arg == "--disk-cache=yes") { - diskCacheEnabled = true; + m_config.setDiskCacheEnabled(true); continue; } if (arg == "--disk-cache=no") { - diskCacheEnabled = false; + m_config.setDiskCacheEnabled(false); continue; } if (arg == "--ignore-ssl-errors=yes") { - ignoreSslErrors = true; + m_config.setIgnoreSslErrors(true); continue; } if (arg == "--ignore-ssl-errors=no") { - ignoreSslErrors = false; + m_config.setIgnoreSslErrors(false); continue; } if (arg == "--local-access-remote=no") { @@ -122,7 +119,7 @@ Phantom::Phantom(QObject *parent) continue; } if (arg.startsWith("--cookies=")) { - cookieFile = arg.mid(10).trimmed(); + m_config.setCookieFile(arg.mid(10).trimmed()); continue; } if (arg.startsWith("--output-encoding=")) { @@ -168,7 +165,7 @@ Phantom::Phantom(QObject *parent) m_scriptFileEnc.setEncoding(m_config.scriptEncoding()); // Provide WebPage with a non-standard Network Access Manager - m_netAccessMan = new NetworkAccessManager(this, diskCacheEnabled, cookieFile, ignoreSslErrors); + m_netAccessMan = new NetworkAccessManager(this, m_config.diskCacheEnabled(), m_config.cookieFile(), m_config.ignoreSslErrors()); m_page->setNetworkAccessManager(m_netAccessMan); connect(m_page, SIGNAL(javaScriptConsoleMessageSent(QString, int, QString)), diff --git a/src/phantomconfig.cpp b/src/phantomconfig.cpp index 1b08b631..5cc820af 100644 --- a/src/phantomconfig.cpp +++ b/src/phantomconfig.cpp @@ -41,6 +41,36 @@ void PhantomConfig::load() resetToDefaults(); } +QString PhantomConfig::cookieFile() const +{ + return m_cookieFile; +} + +void PhantomConfig::setCookieFile(const QString &value) +{ + m_cookieFile = value; +} + +bool PhantomConfig::diskCacheEnabled() const +{ + return m_diskCacheEnabled; +} + +void PhantomConfig::setDiskCacheEnabled(const bool value) +{ + m_diskCacheEnabled = value; +} + +bool PhantomConfig::ignoreSslErrors() const +{ + return m_ignoreSslErrors; +} + +void PhantomConfig::setIgnoreSslErrors(const bool value) +{ + m_ignoreSslErrors = value; +} + QString PhantomConfig::outputEncoding() const { return m_outputEncoding; @@ -100,6 +130,9 @@ void PhantomConfig::setScriptEncoding(const QString &value) // private: void PhantomConfig::resetToDefaults() { + m_cookieFile = QString(); + m_diskCacheEnabled = false; + m_ignoreSslErrors = false; m_outputEncoding = "UTF-8"; m_proxyHost = QString(); m_proxyPort = 1080; diff --git a/src/phantomconfig.h b/src/phantomconfig.h index 22ab8eb1..fce74490 100644 --- a/src/phantomconfig.h +++ b/src/phantomconfig.h @@ -40,6 +40,15 @@ public: void load(); + QString cookieFile() const; + void setCookieFile(const QString &cookieFile); + + bool diskCacheEnabled() const; + void setDiskCacheEnabled(const bool value); + + bool ignoreSslErrors() const; + void setIgnoreSslErrors(const bool value); + QString outputEncoding() const; void setOutputEncoding(const QString &value); @@ -55,6 +64,9 @@ private: void setProxyHost(const QString &value); void setProxyPort(const int value); + QString m_cookieFile; + bool m_diskCacheEnabled; + bool m_ignoreSslErrors; QString m_outputEncoding; QString m_proxyHost; int m_proxyPort;