Commit 9a2d46fb authored by hausmann@webkit.org's avatar hausmann@webkit.org

[Qt] Add persistence support for configuration options in the

inspector.

Patch by Jocelyn Turcotte <jocelyn.turcotte@nokia.com> on 2009-09-18
Reviewed by Simon Hausmann.

* Api/qwebinspector.cpp:
* QtLauncher/main.cpp:
(main):
* WebCoreSupport/InspectorClientQt.cpp:
(WebCore::InspectorClientQt::populateSetting):
(WebCore::InspectorClientQt::storeSetting):
(WebCore::variantToSetting):
(WebCore::settingToVariant):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@48504 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent a05aaad4
......@@ -28,8 +28,6 @@
#include <QResizeEvent>
// TODO: handle the "Always enable" commands with QWebSettings
/*!
\class QWebInspector
\since 4.6
......@@ -44,6 +42,14 @@
\snippet webkitsnippets/qtwebkit_qwebinspector_snippet.cpp 0
\note A QWebInspector will display a blank widget if either:
\list
\o page() is null
\o QWebSettings::DeveloperExtrasEnabled is false
\endlist
\section1 Resources
Most of the resources needed by the inspector are owned by the associated
QWebPage and are allocated the first time that:
\list
......@@ -56,13 +62,16 @@
the first emission of QWebPage::webInspectorTriggered() to save additional
resources.
\note A QWebInspector will display a blank widget if either:
\list
\o page() is null
\o QWebSettings::DeveloperExtrasEnabled is false
\endlist
\section1 Inspector configuration persistence
The inspector allows the user to configure some options through its
interface (e.g. the resource tracking "Always enable" option).
These settings are persisted automatically by QtWebKit using QSettings.
\sa QWebPage::webInspectorTriggered()
However since the QSettings object is instantiated using the empty
constructor, QCoreApplication::setOrganizationName() and
QCoreApplication::setApplicationName() must be called within your
application to enable the persistence of these options.
*/
/*!
......
2009-09-18 Jocelyn Turcotte <jocelyn.turcotte@nokia.com>
Reviewed by Simon Hausmann.
[Qt] Add persistence support for configuration options in the
inspector.
* Api/qwebinspector.cpp:
* QtLauncher/main.cpp:
(main):
* WebCoreSupport/InspectorClientQt.cpp:
(WebCore::InspectorClientQt::populateSetting):
(WebCore::InspectorClientQt::storeSetting):
(WebCore::variantToSetting):
(WebCore::settingToVariant):
2009-09-18 Simon Hausmann <simon.hausmann@nokia.com>
Reviewed by Ariya Hidayat.
......
......@@ -453,6 +453,10 @@ int main(int argc, char **argv)
QWebSettings::globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
QWebSettings::enablePersistentStorage();
// To allow QWebInspector's configuration persistence
QCoreApplication::setOrganizationName("Nokia");
QCoreApplication::setApplicationName("QtLauncher");
const QStringList args = app.arguments();
if (args.contains(QLatin1String("-r"))) {
......
......@@ -37,6 +37,7 @@
#include "qwebpage_p.h"
#include "qwebview.h"
#include <QtCore/QSettings>
#include <QtCore/QCoreApplication>
#include "InspectorController.h"
......@@ -46,6 +47,12 @@
namespace WebCore {
static const QLatin1String settingStoragePrefix("Qt/QtWebKit/QWebInspector/");
static const QLatin1String settingStorageTypeSuffix(".type");
static InspectorController::Setting variantToSetting(const QVariant& qvariant);
static QVariant settingToVariant(const InspectorController::Setting& icSetting);
class InspectorClientWebPage : public QWebPage {
Q_OBJECT
friend class InspectorClientQt;
......@@ -66,7 +73,6 @@ public:
}
};
InspectorClientQt::InspectorClientQt(QWebPage* page)
: m_inspectedWebPage(page)
{}
......@@ -169,12 +175,34 @@ void InspectorClientQt::updateWindowTitle()
void InspectorClientQt::populateSetting(const String& key, InspectorController::Setting& setting)
{
notImplemented();
QSettings qsettings;
if (qsettings.status() == QSettings::AccessError) {
// QCoreApplication::setOrganizationName and QCoreApplication::setApplicationName haven't been called
qWarning("QWebInspector: QSettings couldn't read configuration setting [%s].",
qPrintable(static_cast<QString>(key)));
return;
}
QString settingKey(settingStoragePrefix + key);
QString storedValueType = qsettings.value(settingKey + settingStorageTypeSuffix).toString();
QVariant storedValue = qsettings.value(settingKey);
storedValue.convert(QVariant::nameToType(storedValueType.toAscii().data()));
setting = variantToSetting(storedValue);
}
void InspectorClientQt::storeSetting(const String& key, const InspectorController::Setting& setting)
{
notImplemented();
QSettings qsettings;
if (qsettings.status() == QSettings::AccessError) {
qWarning("QWebInspector: QSettings couldn't persist configuration setting [%s].",
qPrintable(static_cast<QString>(key)));
return;
}
QVariant valueToStore = settingToVariant(setting);
QString settingKey(settingStoragePrefix + key);
qsettings.setValue(settingKey, valueToStore);
qsettings.setValue(settingKey + settingStorageTypeSuffix, QVariant::typeToName(valueToStore.type()));
}
void InspectorClientQt::removeSetting(const String& key)
......@@ -182,6 +210,68 @@ void InspectorClientQt::removeSetting(const String& key)
notImplemented();
}
static InspectorController::Setting variantToSetting(const QVariant& qvariant)
{
InspectorController::Setting retVal;
switch (qvariant.type()) {
case QVariant::Bool:
retVal.set(qvariant.toBool());
break;
case QVariant::Double:
retVal.set(qvariant.toDouble());
break;
case QVariant::Int:
retVal.set((long)qvariant.toInt());
break;
case QVariant::String:
retVal.set(qvariant.toString());
break;
case QVariant::StringList: {
QStringList qsList = qvariant.toStringList();
int listCount = qsList.count();
Vector<String> vector(listCount);
for (int i = 0; i < listCount; ++i)
vector[i] = qsList[i];
retVal.set(vector);
break;
}
}
return retVal;
}
static QVariant settingToVariant(const InspectorController::Setting& icSetting)
{
QVariant retVal;
switch (icSetting.type()) {
case InspectorController::Setting::StringType:
retVal.setValue(static_cast<QString>(icSetting.string()));
break;
case InspectorController::Setting::StringVectorType: {
const Vector<String>& vector = icSetting.stringVector();
Vector<String>::const_iterator iter;
QStringList qsList;
for (iter = vector.begin(); iter != vector.end(); ++iter)
qsList << *iter;
retVal.setValue(qsList);
break;
}
case InspectorController::Setting::DoubleType:
retVal.setValue(icSetting.doubleValue());
break;
case InspectorController::Setting::IntegerType:
retVal.setValue((int)icSetting.integerValue());
break;
case InspectorController::Setting::BooleanType:
retVal.setValue(icSetting.booleanValue());
break;
}
return retVal;
}
}
#include "InspectorClientQt.moc"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment