diff --git a/src/config.cpp b/src/config.cpp index 8f41249a93..1f38c1e989 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -53,9 +53,11 @@ static const struct QCommandLineConfigEntry flags[] = { { QCommandLine::Option, '\0', "disk-cache", "Enables disk cache: 'true' or 'false' (default)", QCommandLine::Optional }, { QCommandLine::Option, '\0', "ignore-ssl-errors", "Ignores SSL errors (expired/self-signed certificate errors): 'true' or 'false' (default)", QCommandLine::Optional }, { QCommandLine::Option, '\0', "load-images", "Loads all inlined images: 'true' (default) or 'false'", QCommandLine::Optional }, - { QCommandLine::Option, '\0', "local-storage-path", "Specifies the location for offline local storage", QCommandLine::Optional }, - { QCommandLine::Option, '\0', "local-storage-quota", "Sets the maximum size of the offline local storage (in KB)", QCommandLine::Optional }, { QCommandLine::Option, '\0', "local-url-access", "Allows use of 'file:///' URLs: 'true' (default) or 'false'", QCommandLine::Optional }, + { QCommandLine::Option, '\0', "local-storage-path", "Specifies the location for local storage", QCommandLine::Optional }, + { QCommandLine::Option, '\0', "local-storage-quota", "Sets the maximum size of the local storage (in KB)", QCommandLine::Optional }, + { QCommandLine::Option, '\0', "offline-storage-path", "Specifies the location for offline storage", QCommandLine::Optional }, + { QCommandLine::Option, '\0', "offline-storage-quota", "Sets the maximum size of the offline storage (in KB)", QCommandLine::Optional }, { QCommandLine::Option, '\0', "local-to-remote-url-access", "Allows local content to access remote URL: 'true' or 'false' (default)", QCommandLine::Optional }, { QCommandLine::Option, '\0', "max-disk-cache-size", "Limits the size of the disk cache (in KB)", QCommandLine::Optional }, { QCommandLine::Option, '\0', "output-encoding", "Sets the encoding for the terminal output, default is 'utf8'", QCommandLine::Optional }, @@ -223,6 +225,28 @@ void Config::setOfflineStorageDefaultQuota(int offlineStorageDefaultQuota) m_offlineStorageDefaultQuota = offlineStorageDefaultQuota * 1024; } + +QString Config::localStoragePath() const +{ + return m_localStoragePath; +} + +void Config::setLocalStoragePath(const QString &value) +{ + QDir dir(value); + m_localStoragePath = dir.absolutePath(); +} + +int Config::localStorageDefaultQuota() const +{ + return m_localStorageDefaultQuota; +} + +void Config::setLocalStorageDefaultQuota(int localStorageDefaultQuota) +{ + m_localStorageDefaultQuota = localStorageDefaultQuota * 1024; +} + bool Config::diskCacheEnabled() const { return m_diskCacheEnabled; @@ -546,6 +570,8 @@ void Config::resetToDefaults() m_cookiesFile = QString(); m_offlineStoragePath = QString(); m_offlineStorageDefaultQuota = -1; + m_localStoragePath = QString(); + m_localStorageDefaultQuota = -1; m_diskCacheEnabled = false; m_maxDiskCacheSize = -1; m_ignoreSslErrors = false; @@ -698,10 +724,18 @@ void Config::handleOption(const QString& option, const QVariant& value) } if (option == "local-storage-path") { - setOfflineStoragePath(value.toString()); + setLocalStoragePath(value.toString()); } if (option == "local-storage-quota") { + setLocalStorageDefaultQuota(value.toInt()); + } + + if (option == "offline-storage-path") { + setOfflineStoragePath(value.toString()); + } + + if (option == "offline-storage-quota") { setOfflineStorageDefaultQuota(value.toInt()); } diff --git a/src/config.h b/src/config.h index 8a60a8b44d..0891038eb7 100644 --- a/src/config.h +++ b/src/config.h @@ -54,6 +54,8 @@ class Config: public QObject Q_PROPERTY(QString scriptEncoding READ scriptEncoding WRITE setScriptEncoding) Q_PROPERTY(bool webSecurityEnabled READ webSecurityEnabled WRITE setWebSecurityEnabled) Q_PROPERTY(QString offlineStoragePath READ offlineStoragePath WRITE setOfflineStoragePath) + Q_PROPERTY(QString localStoragePath READ localStoragePath WRITE setLocalStoragePath) + Q_PROPERTY(int localStorageDefaultQuota READ localStorageDefaultQuota WRITE setLocalStorageDefaultQuota) Q_PROPERTY(int offlineStorageDefaultQuota READ offlineStorageDefaultQuota WRITE setOfflineStorageDefaultQuota) Q_PROPERTY(bool printDebugMessages READ printDebugMessages WRITE setPrintDebugMessages) Q_PROPERTY(bool javascriptCanOpenWindows READ javascriptCanOpenWindows WRITE setJavascriptCanOpenWindows) @@ -90,6 +92,12 @@ class Config: public QObject int offlineStorageDefaultQuota() const; void setOfflineStorageDefaultQuota(int offlineStorageDefaultQuota); + QString localStoragePath() const; + void setLocalStoragePath(const QString &value); + + int localStorageDefaultQuota() const; + void setLocalStorageDefaultQuota(int localStorageDefaultQuota); + bool diskCacheEnabled() const; void setDiskCacheEnabled(const bool value); @@ -214,6 +222,8 @@ public slots: QString m_cookiesFile; QString m_offlineStoragePath; int m_offlineStorageDefaultQuota; + QString m_localStoragePath; + int m_localStorageDefaultQuota; bool m_diskCacheEnabled; int m_maxDiskCacheSize; bool m_ignoreSslErrors; diff --git a/src/webpage.cpp b/src/webpage.cpp index c3b36c98e1..630774d5a8 100644 --- a/src/webpage.cpp +++ b/src/webpage.cpp @@ -413,7 +413,12 @@ WebPage::WebPage(QObject* parent, const QUrl& baseUrl) m_customWebPage->settings()->setAttribute(QWebSettings::FrameFlatteningEnabled, true); m_customWebPage->settings()->setAttribute(QWebSettings::LocalStorageEnabled, true); - m_customWebPage->settings()->setLocalStoragePath(QStandardPaths::writableLocation(QStandardPaths::DataLocation)); + + if (phantomCfg->localStoragePath().isEmpty()) { + m_customWebPage->settings()->setLocalStoragePath(QStandardPaths::writableLocation(QStandardPaths::DataLocation)); + } else { + m_customWebPage->settings()->setLocalStoragePath(phantomCfg->localStoragePath()); + } // Custom network access manager to allow traffic monitoring. m_networkAccessManager = new NetworkAccessManager(this, phantomCfg);