2011-02-04 Kundu Suchismita <suchi.kundu@nokia.com>
[WebKit.git] / Tools / QtTestBrowser / launcherwindow.cpp
index 1a4d28f670837cd6fc1a826990f6c93c6eab2740..21f43c56aa731cb38fd451620800d3e5a6469574 100644 (file)
@@ -56,6 +56,9 @@ LauncherWindow::LauncherWindow(WindowOptions* data, QGraphicsScene* sharedScene)
 LauncherWindow::~LauncherWindow()
 {
     grabZoomKeys(false);
+
+    if (page())
+        page()->setQnamThreaded(false);
 }
 
 void LauncherWindow::init()
@@ -93,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);
@@ -139,6 +143,10 @@ void LauncherWindow::initializeView()
 
     if (url.isValid())
         page()->mainFrame()->load(url);
+    else  {
+        setAddressUrl(m_inputUrl);
+        m_inputUrl = QString();
+    }
 }
 
 void LauncherWindow::applyPrefs()
@@ -163,6 +171,7 @@ void LauncherWindow::applyPrefs()
 
 void LauncherWindow::createChrome()
 {
+#ifndef QT_NO_SHORTCUT
     QMenu* fileMenu = menuBar()->addMenu("&File");
     fileMenu->addAction("New Window", this, SLOT(newWindow()), QKeySequence::New);
     fileMenu->addAction(tr("Open File..."), this, SLOT(openFile()), QKeySequence::Open);
@@ -170,7 +179,9 @@ void LauncherWindow::createChrome()
     fileMenu->addAction("Close Window", this, SLOT(close()), QKeySequence::Close);
     fileMenu->addSeparator();
     fileMenu->addAction("Take Screen Shot...", this, SLOT(screenshot()));
+#ifndef QT_NO_PRINTER
     fileMenu->addAction(tr("Print..."), this, SLOT(print()), QKeySequence::Print);
+#endif
     fileMenu->addSeparator();
     fileMenu->addAction("Quit", QApplication::instance(), SLOT(closeAllWindows()), QKeySequence(Qt::CTRL | Qt::Key_Q));
 
@@ -253,13 +264,21 @@ void LauncherWindow::createChrome()
 
     toolsMenu->addSeparator();
 
-    QAction* toggleInterruptingJavaScripteEnabled = toolsMenu->addAction("Enable interrupting js scripts", this, SLOT(toggleInterruptingJavaScriptEnabled(bool)));
-    toggleInterruptingJavaScripteEnabled->setCheckable(true);
-    toggleInterruptingJavaScripteEnabled->setChecked(false);
+    QAction* toggleLocalStorage = toolsMenu->addAction("Enable Local Storage", this, SLOT(toggleLocalStorage(bool)));
+    toggleLocalStorage->setCheckable(true);
+    toggleLocalStorage->setChecked(m_windowOptions.useLocalStorage);
 
-    QAction* toggleJavascriptCanOpenWindows = toolsMenu->addAction("Enable js popup windows", this, SLOT(toggleJavascriptCanOpenWindows(bool)));
-    toggleJavascriptCanOpenWindows->setCheckable(true);
-    toggleJavascriptCanOpenWindows->setChecked(false);
+    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();
 
@@ -368,6 +387,26 @@ void LauncherWindow::createChrome()
     showFPS->setEnabled(isGraphicsBased());
     showFPS->connect(toggleGraphicsView, SIGNAL(toggled(bool)), SLOT(setEnabled(bool)));
     showFPS->setChecked(m_windowOptions.showFrameRate);
+
+    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);
+
+    QAction* toggleJavascriptCanOpenWindows = settingsMenu->addAction("Enable js popup windows", this, SLOT(toggleJavascriptCanOpenWindows(bool)));
+    toggleJavascriptCanOpenWindows->setCheckable(true);
+    toggleJavascriptCanOpenWindows->setChecked(false);
+
+#endif
 }
 
 bool LauncherWindow::isGraphicsBased() const
@@ -522,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)
@@ -547,6 +591,7 @@ void LauncherWindow::zoomAnimationFinished()
 
 void LauncherWindow::applyZoom()
 {
+#ifndef QT_NO_ANIMATION
     if (isGraphicsBased() && page()->settings()->testAttribute(QWebSettings::TiledBackingStoreEnabled)) {
         QGraphicsWebView* view = static_cast<WebViewGraphicsBased*>(m_view)->graphicsWebView();
         view->setTiledBackingStoreFrozen(true);
@@ -564,6 +609,7 @@ void LauncherWindow::applyZoom()
         m_zoomAnimation->start();
         return;
     }
+#endif
     page()->mainFrame()->setZoomFactor(qreal(m_currentZoom) / 100.0);
 }
 
@@ -620,12 +666,14 @@ void LauncherWindow::screenshot()
     label->show();
 #endif
 
+#ifndef QT_NO_FILEDIALOG
     QString fileName = QFileDialog::getSaveFileName(label, "Screenshot");
     if (!fileName.isEmpty()) {
         pixmap.save(fileName, "png");
         if (label)
             label->setWindowTitle(QString("Screenshot - Saved at %1").arg(fileName));
     }
+#endif
 
 #if defined(QT_CONFIGURED_WITH_OPENGL)
     toggleQGLWidgetViewport(m_windowOptions.useQGLWidgetViewport);
@@ -657,6 +705,7 @@ void LauncherWindow::dumpHtml()
 
 void LauncherWindow::selectElements()
 {
+#ifndef QT_NO_INPUTDIALOG
     bool ok;
     QString str = QInputDialog::getText(this, "Select elements", "Choose elements",
                                         QLineEdit::Normal, "a", &ok);
@@ -669,6 +718,7 @@ void LauncherWindow::selectElements()
         statusBar()->showMessage(QString("%1 element(s) selected").arg(result.count()), 5000);
 #endif
     }
+#endif
 }
 
 void LauncherWindow::setTouchMocking(bool on)
@@ -756,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)
 {
@@ -821,6 +881,7 @@ void LauncherWindow::showUserAgentDialog()
     QVBoxLayout* layout = new QVBoxLayout(dialog);
     dialog->setLayout(layout);
 
+#ifndef QT_NO_COMBOBOX
     QComboBox* combo = new QComboBox(dialog);
     combo->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength);
     combo->setEditable(true);
@@ -829,6 +890,7 @@ void LauncherWindow::showUserAgentDialog()
 
     int index = combo->findText(page()->userAgentForUrl(QUrl()));
     combo->setCurrentIndex(index);
+#endif
 
     QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
             | QDialogButtonBox::Cancel, Qt::Horizontal, dialog);
@@ -836,11 +898,13 @@ void LauncherWindow::showUserAgentDialog()
     connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject()));
     layout->addWidget(buttonBox);
 
+#ifndef QT_NO_COMBOBOX
     if (dialog->exec() && !combo->currentText().isEmpty()) {
         page()->setUserAgent(combo->currentText());
         if (!items.contains(combo->currentText()))
             settings.setValue("CustomUserAgent", combo->currentText());
     }
+#endif
 
     delete dialog;
 }
@@ -856,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);