diff --git a/src/config.cpp b/src/config.cpp index 6f2e5186..71cdec4f 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -84,6 +84,10 @@ void Config::processArgs(const QStringList &args) setDiskCacheEnabled(false); continue; } + if (arg.startsWith("--max-disk-cache-size=")) { + setMaxDiskCacheSize(arg.mid(arg.indexOf("=") + 1).trimmed().toInt()); + continue; + } if (arg == "--ignore-ssl-errors=yes") { setIgnoreSslErrors(true); continue; @@ -208,6 +212,16 @@ void Config::setDiskCacheEnabled(const bool value) m_diskCacheEnabled = value; } +int Config::maxDiskCacheSize() const +{ + return m_maxDiskCacheSize; +} + +void Config::setMaxDiskCacheSize(int maxDiskCacheSize) +{ + m_maxDiskCacheSize = maxDiskCacheSize; +} + bool Config::ignoreSslErrors() const { return m_ignoreSslErrors; @@ -379,6 +393,7 @@ void Config::resetToDefaults() m_autoLoadImages = true; m_cookieFile.clear(); m_diskCacheEnabled = false; + m_maxDiskCacheSize = -1; m_ignoreSslErrors = false; m_localAccessRemote = false; m_outputEncoding = "UTF-8"; diff --git a/src/config.h b/src/config.h index 7d436161..21be4f5b 100644 --- a/src/config.h +++ b/src/config.h @@ -39,6 +39,7 @@ class Config: QObject Q_OBJECT Q_PROPERTY(QString cookieFile READ cookieFile WRITE setCookieFile) Q_PROPERTY(bool diskCacheEnabled READ diskCacheEnabled WRITE setDiskCacheEnabled) + Q_PROPERTY(int maxDiskCacheSize READ maxDiskCacheSize WRITE setMaxDiskCacheSize) Q_PROPERTY(bool ignoreSslErrors READ ignoreSslErrors WRITE setIgnoreSslErrors) Q_PROPERTY(bool localAccessRemote READ localAccessRemote WRITE setLocalAccessRemote) Q_PROPERTY(QString outputEncoding READ outputEncoding WRITE setOutputEncoding) @@ -63,6 +64,9 @@ public: bool diskCacheEnabled() const; void setDiskCacheEnabled(const bool value); + int maxDiskCacheSize() const; + void setMaxDiskCacheSize(int maxDiskCacheSize); + bool ignoreSslErrors() const; void setIgnoreSslErrors(const bool value); @@ -110,6 +114,7 @@ private: bool m_autoLoadImages; QString m_cookieFile; bool m_diskCacheEnabled; + int m_maxDiskCacheSize; bool m_ignoreSslErrors; bool m_localAccessRemote; QString m_outputEncoding; diff --git a/src/networkaccessmanager.cpp b/src/networkaccessmanager.cpp index a899acf4..cdb50170 100644 --- a/src/networkaccessmanager.cpp +++ b/src/networkaccessmanager.cpp @@ -67,7 +67,7 @@ static const char *toString(QNetworkAccessManager::Operation op) } // public: -NetworkAccessManager::NetworkAccessManager(QObject *parent, bool diskCacheEnabled, QString cookieFile, bool ignoreSslErrors, QString authUser, QString authPass) +NetworkAccessManager::NetworkAccessManager(QObject *parent, bool diskCacheEnabled, QString cookieFile, bool ignoreSslErrors, QString authUser, QString authPass, int maxCacheSize) : QNetworkAccessManager(parent) , m_networkDiskCache(0) , m_ignoreSslErrors(ignoreSslErrors) @@ -82,6 +82,8 @@ NetworkAccessManager::NetworkAccessManager(QObject *parent, bool diskCacheEnable if (diskCacheEnabled) { m_networkDiskCache = new QNetworkDiskCache(); m_networkDiskCache->setCacheDirectory(QDesktopServices::storageLocation(QDesktopServices::CacheLocation)); + if (maxCacheSize >= 0) + m_networkDiskCache->setMaximumCacheSize(maxCacheSize * 1024); setCache(m_networkDiskCache); } diff --git a/src/networkaccessmanager.h b/src/networkaccessmanager.h index 350bac5d..f8fc5025 100644 --- a/src/networkaccessmanager.h +++ b/src/networkaccessmanager.h @@ -46,7 +46,8 @@ class NetworkAccessManager : public QNetworkAccessManager public: NetworkAccessManager(QObject *parent = 0, bool diskCacheEnabled = false, QString cookieFile = QString(), bool ignoreSslErrors = false, - QString authUser = QString(), QString authPass = QString()); + QString authUser = QString(), QString authPass = QString(), + int maxCacheSize = -1); virtual ~NetworkAccessManager(); protected: diff --git a/src/phantom.cpp b/src/phantom.cpp index 0d2e9039..68d0d67c 100644 --- a/src/phantom.cpp +++ b/src/phantom.cpp @@ -91,7 +91,8 @@ Phantom::Phantom(QObject *parent) m_scriptFileEnc.setEncoding(m_config.scriptEncoding()); // Provide WebPage with a non-standard Network Access Manager - m_netAccessMan = new NetworkAccessManager(this, m_config.diskCacheEnabled(), m_config.cookieFile(), m_config.ignoreSslErrors(), m_config.authUser(), m_config.authPass()); + m_netAccessMan = new NetworkAccessManager(this, m_config.diskCacheEnabled(), + m_config.cookieFile(), m_config.ignoreSslErrors(), m_config.authUser(), m_config.authPass(), m_config.maxDiskCacheSize()); m_page->setNetworkAccessManager(m_netAccessMan); connect(m_page, SIGNAL(javaScriptConsoleMessageSent(QString, int, QString)), diff --git a/src/usage.txt b/src/usage.txt index 31f07bd2..360322bc 100644 --- a/src/usage.txt +++ b/src/usage.txt @@ -9,6 +9,7 @@ Options: --proxy=address:port Sets the network proxy (e.g. "--proxy=http://192.168.1.42:8080"). --auth=username:password Sets the authentication username and password (e.g. "--auth=username:password"). --disk-cache=[yes|no] Enables disk cache (at desktop services cache storage location, default is 'no'). + --max-disk-cache-size=size Limits the size of disk cache (in KB). --ignore-ssl-errors=[yes|no] Ignores SSL errors (i.e. expired or self-signed certificate errors). --local-access-remote=[yes|no] Local content can access remote URL (default is 'no'). --output-encoding Sets (if available) the encoding used for terminal output (default is 'utf8').