2011-02-04 Kundu Suchismita <suchi.kundu@nokia.com>
[WebKit.git] / Tools / QtTestBrowser / launcherwindow.cpp
index 067b14619e30d8d89c41151d2019ad66355f115e..21f43c56aa731cb38fd451620800d3e5a6469574 100644 (file)
@@ -96,6 +96,7 @@ void LauncherWindow::initializeView()
 {
     delete m_view;
 
+    m_inputUrl = addressUrl();
     QUrl url = page()->mainFrame()->url();
     setPage(new WebPage(this));
     page()->setQnamThreaded(m_windowOptions.useThreadedQnam);
@@ -142,6 +143,10 @@ void LauncherWindow::initializeView()
 
     if (url.isValid())
         page()->mainFrame()->load(url);
+    else  {
+        setAddressUrl(m_inputUrl);
+        m_inputUrl = QString();
+    }
 }
 
 void LauncherWindow::applyPrefs()
@@ -259,6 +264,24 @@ void LauncherWindow::createChrome()
 
     toolsMenu->addSeparator();
 
+    QAction* toggleLocalStorage = toolsMenu->addAction("Enable Local Storage", this, SLOT(toggleLocalStorage(bool)));
+    toggleLocalStorage->setCheckable(true);
+    toggleLocalStorage->setChecked(m_windowOptions.useLocalStorage);
+
+    QAction* toggleOfflineStorageDatabase = toolsMenu->addAction("Enable Offline Storage Database", this, SLOT(toggleOfflineStorageDatabase(bool)));
+    toggleOfflineStorageDatabase->setCheckable(true);
+    toggleOfflineStorageDatabase->setChecked(m_windowOptions.useOfflineStorageDatabase);
+
+    QAction* toggleOfflineWebApplicationCache = toolsMenu->addAction("Enable Offline Web Application Cache", this, SLOT(toggleOfflineWebApplicationCache(bool)));
+    toggleOfflineWebApplicationCache->setCheckable(true);
+    toggleOfflineWebApplicationCache->setChecked(m_windowOptions.useOfflineWebApplicationCache);
+
+    QAction* offlineStorageDefaultQuotaAction = toolsMenu->addAction("Set Offline Storage Default Quota Size", this, SLOT(setOfflineStorageDefaultQuota()));
+    offlineStorageDefaultQuotaAction->setCheckable(true);
+    offlineStorageDefaultQuotaAction->setChecked(m_windowOptions.offlineStorageDefaultQuotaSize);
+
+    toolsMenu->addSeparator();
+
     QAction* userAgentAction = toolsMenu->addAction("Change User Agent", this, SLOT(showUserAgentDialog()));
     userAgentAction->setShortcut(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_U));
 
@@ -367,6 +390,14 @@ void LauncherWindow::createChrome()
 
     QMenu* settingsMenu = menuBar()->addMenu("&Settings");
 
+    QAction* toggleAutoLoadImages = settingsMenu->addAction("Disable Auto Load Images", this, SLOT(toggleAutoLoadImages(bool)));
+    toggleAutoLoadImages->setCheckable(true);
+    toggleAutoLoadImages->setChecked(false);
+
+    QAction* togglePlugins = settingsMenu->addAction("Disable Plugins", this, SLOT(togglePlugins(bool)));
+    togglePlugins->setCheckable(true);
+    togglePlugins->setChecked(false);
+
     QAction* toggleInterruptingJavaScripteEnabled = settingsMenu->addAction("Enable interrupting js scripts", this, SLOT(toggleInterruptingJavaScriptEnabled(bool)));
     toggleInterruptingJavaScripteEnabled->setCheckable(true);
     toggleInterruptingJavaScripteEnabled->setChecked(false);
@@ -530,8 +561,13 @@ void LauncherWindow::loadStarted()
 void LauncherWindow::loadFinished()
 {
     QUrl url = page()->mainFrame()->url();
-    setAddressUrl(url.toString(QUrl::RemoveUserInfo));
     addCompleterEntry(url);
+    if (m_inputUrl.isEmpty())
+        setAddressUrl(url.toString(QUrl::RemoveUserInfo));
+    else {
+        setAddressUrl(m_inputUrl);
+        m_inputUrl = QString();
+    }
 }
 
 void LauncherWindow::showLinkHover(const QString &link, const QString &toolTip)
@@ -770,6 +806,16 @@ void LauncherWindow::toggleJavascriptCanOpenWindows(bool enable)
     page()->settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, enable);
 }
 
+void LauncherWindow::toggleAutoLoadImages(bool enable)
+{
+    page()->settings()->setAttribute(QWebSettings::AutoLoadImages, !enable);
+}
+
+void LauncherWindow::togglePlugins(bool enable)
+{
+    page()->settings()->setAttribute(QWebSettings::PluginsEnabled, !enable);
+}
+
 #if defined(QT_CONFIGURED_WITH_OPENGL)
 void LauncherWindow::toggleQGLWidgetViewport(bool enable)
 {
@@ -874,6 +920,38 @@ void LauncherWindow::updateFPS(int fps)
 #endif
 }
 
+void LauncherWindow::toggleLocalStorage(bool toggle)
+{
+    m_windowOptions.useLocalStorage = toggle;
+    page()->settings()->setAttribute(QWebSettings::LocalStorageEnabled, toggle);
+}
+
+void LauncherWindow::toggleOfflineStorageDatabase(bool toggle)
+{
+    m_windowOptions.useOfflineStorageDatabase = toggle;
+    page()->settings()->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, toggle);
+}
+
+void LauncherWindow::toggleOfflineWebApplicationCache(bool toggle)
+{
+    m_windowOptions.useOfflineWebApplicationCache = toggle;
+    page()->settings()->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, toggle);
+}
+
+void LauncherWindow::setOfflineStorageDefaultQuota()
+{
+    // For command line execution, quota size is taken from command line.   
+    if (m_windowOptions.offlineStorageDefaultQuotaSize)
+        page()->settings()->setOfflineStorageDefaultQuota(m_windowOptions.offlineStorageDefaultQuotaSize);
+    else {
+        bool ok;
+        // Maximum size is set to 25 * 1024 * 1024.
+        int quotaSize = QInputDialog::getInt(this, "Offline Storage Default Quota Size" , "Quota Size", 0, 0, 26214400, 1, &ok);
+        if (ok) 
+            page()->settings()->setOfflineStorageDefaultQuota(quotaSize);
+    }
+}
+
 LauncherWindow* LauncherWindow::newWindow()
 {
     LauncherWindow* mw = new LauncherWindow(&m_windowOptions);