[SCM] WebKit Debian packaging branch, webkit-1.1, updated. upstream/1.1.20-204-g221d8e8

kenneth at webkit.org kenneth at webkit.org
Wed Feb 10 22:11:26 UTC 2010


The following commit has been merged in the webkit-1.1 branch:
commit 6ea056af02d82264b8f673236bb416854b442e60
Author: kenneth at webkit.org <kenneth at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Wed Feb 3 21:44:51 2010 +0000

    [Qt] QtLauncher, refactor argument handling in preparation of merge
    with QGVLauncher
    
    Reviewed by Ariya Hidayat.
    
    * QtLauncher/main.cpp:
    (LauncherApplication::urls):
    (LauncherApplication::isRobotized):
    (LauncherApplication::applyDefaultSettings):
    (LauncherApplication::LauncherApplication):
    (LauncherApplication::formatKeys):
    (LauncherApplication::enumToKeys):
    (fail):
    (LauncherApplication::handleUserOptions):
    (main):
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@54297 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKitTools/ChangeLog b/WebKitTools/ChangeLog
index e4bda7d..1ff7afe 100644
--- a/WebKitTools/ChangeLog
+++ b/WebKitTools/ChangeLog
@@ -1,3 +1,21 @@
+2010-02-03  Kenneth Rohde Christiansen  <kenneth at webkit.org>
+
+        Reviewed by Ariya Hidayat.
+
+        [Qt] QtLauncher, refactor argument handling in preparation of merge
+        with QGVLauncher
+
+        * QtLauncher/main.cpp:
+        (LauncherApplication::urls):
+        (LauncherApplication::isRobotized):
+        (LauncherApplication::applyDefaultSettings):
+        (LauncherApplication::LauncherApplication):
+        (LauncherApplication::formatKeys):
+        (LauncherApplication::enumToKeys):
+        (fail):
+        (LauncherApplication::handleUserOptions):
+        (main):
+
 2010-02-03  Csaba Osztrogonác  <ossy at webkit.org>
 
         Rubber-stamped by Ariya Hidayat.
diff --git a/WebKitTools/QtLauncher/main.cpp b/WebKitTools/QtLauncher/main.cpp
index 081b8f0..31bca8e 100644
--- a/WebKitTools/QtLauncher/main.cpp
+++ b/WebKitTools/QtLauncher/main.cpp
@@ -525,8 +525,6 @@ QObject* WebPage::createPlugin(const QString &classId, const QUrl&, const QStrin
 }
 
 
-#include "main.moc"
-
 int launcherMain(const QApplication& app)
 {
 #ifndef NDEBUG
@@ -539,60 +537,185 @@ int launcherMain(const QApplication& app)
 #endif
 }
 
-int main(int argc, char **argv)
-{
-    QApplication app(argc, argv);
-    QString defaultUrl = QString("file://%1/%2").arg(QDir::homePath()).arg(QLatin1String("index.html"));
+class LauncherApplication : public QApplication {
+    Q_OBJECT
 
-    QWebSettings::setMaximumPagesInCache(4);
+public:
+    LauncherApplication(int& argc, char** argv);
+    QStringList urls() const { return m_urls; }
+    bool isRobotized() const { return m_isRobotized; }
+
+private:
+    void handleUserOptions();
+    void applyDefaultSettings();
 
-    app.setApplicationName("QtLauncher");
-    app.setApplicationVersion("0.1");
+    QList<QString> enumToKeys(const QMetaObject o, const QString& name, const QString& strip);
+    QString formatKeys(QList<QString> keys);
+
+private:
+    bool m_isRobotized;
+    QStringList m_urls;
+};
+
+void LauncherApplication::applyDefaultSettings()
+{
+    QWebSettings::setMaximumPagesInCache(4);
 
     QWebSettings::setObjectCacheCapacities((16*1024*1024) / 8, (16*1024*1024) / 8, 16*1024*1024);
 
     QWebSettings::globalSettings()->setAttribute(QWebSettings::PluginsEnabled, true);
     QWebSettings::globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
     QWebSettings::enablePersistentStorage();
+}
 
+LauncherApplication::LauncherApplication(int& argc, char** argv)
+    : QApplication(argc, argv)
+    , m_isRobotized(false)
+{
     // To allow QWebInspector's configuration persistence
-    QCoreApplication::setOrganizationName("Nokia");
-    QCoreApplication::setApplicationName("QtLauncher");
+    setOrganizationName("Nokia");
+    setApplicationName("QtLauncher");
+    setApplicationVersion("0.1");
 
-    const QStringList args = app.arguments();
+    applyDefaultSettings();
 
-    if (args.contains(QLatin1String("-r"))) {
-        // robotized
-        QString listFile = args.at(2);
-        if (!(args.count() == 3) && QFile::exists(listFile)) {
-            qDebug() << "Usage: QtLauncher -r listfile";
-            exit(0);
+    handleUserOptions();
+}
+
+QString LauncherApplication::formatKeys(QList<QString> keys)
+{
+    QString result;
+    for (int i = 0; i < keys.count() - 1; i++)
+        result.append(keys.at(i) + "|");
+    result.append(keys.last());
+    return result;
+}
+
+QList<QString> LauncherApplication::enumToKeys(const QMetaObject o, const QString& name, const QString& strip)
+{
+    QList<QString> list;
+
+    int enumIndex = o.indexOfEnumerator(name.toLatin1().data());
+    QMetaEnum enumerator = o.enumerator(enumIndex);
+
+    if (enumerator.isValid()) {
+        for (int i = 0; i < enumerator.keyCount(); i++) {
+            QString key(enumerator.valueToKey(i));
+            list.append(key.remove(strip));
         }
+    }
+
+    return list;
+}
+
+static void fail(const QString& errorMsg)
+{
+    qDebug() << "ERROR:" << errorMsg.toLatin1().data();
+    exit(1);
+}
+
+void LauncherApplication::handleUserOptions()
+{
+    QStringList args = arguments();
+    QFileInfo program(args.at(0));
+    QString programName("QtLauncher");
+    if (program.exists())
+        programName = program.baseName();
+
+    QList<QString> updateModes(enumToKeys(QGraphicsView::staticMetaObject,
+            "ViewportUpdateMode", "ViewportUpdate"));
+
+    if (args.contains("--help")) {
+        qDebug() << "Usage:" << programName.toLatin1().data()
+             << "[--graphicsbased]"
+             << "[--compositing]"
+             << QString("[--viewport-update-mode %1]").arg(formatKeys(updateModes)).toLatin1().data()
+             << "[--cache-webview]"
+             << "[-r list]"
+             << "URLs";
+        exit(0);
+    }
+
+    bool useGraphicsView = false;
+
+    if (args.contains("--graphicsbased"))
+        useGraphicsView = true;
+
+    if (args.contains("--compositing") && useGraphicsView)
+        QWebSettings::globalSettings()->setAttribute(QWebSettings::AcceleratedCompositingEnabled, true);
+
+    if (args.contains("--cache-webview") && useGraphicsView)
+        ; // view->setCacheMode(QGraphicsItem::DeviceCoordinateCache);
+
+    int modeIndex = args.indexOf("--viewport-update-mode");
+    if (modeIndex != -1 && ++modeIndex < args.count() && !args.at(modeIndex).startsWith("-")) {
+        QString mode = args.takeAt(modeIndex);
+        if (useGraphicsView) {
+            int idx = updateModes.indexOf(mode);
+            if (idx != -1) {
+                ; // view->setViewportUpdateMode(static_cast<QGraphicsView::ViewportUpdateMode>(idx));
+            } else {
+                fail(QString("--viewport-update-mode value has to be one of [%1]")
+                    .arg(formatKeys(updateModes)).toLatin1().data());
+            }
+        }
+    }
+
+    int robotIndex = args.indexOf("-r");
+    if (robotIndex != -1) {
+        if (++robotIndex < args.count() && !args.at(robotIndex).startsWith("-")) {
+            QString listFile = args.takeAt(robotIndex);
+            if (!QFile::exists(listFile))
+                fail(QString("The list file supplied to -r does not exist."));
+            else {
+                m_isRobotized = true;
+                m_urls = QStringList(listFile);
+                return;
+            }
+        }
+        else
+            fail(QString("-r needs a list file to start in robotized mode"));
+    }
+
+    int lastArg = args.lastIndexOf(QRegExp("^-.*"));
+    m_urls = (lastArg != -1) ? args.mid(++lastArg) : args.mid(1);
+}
+
+
+int main(int argc, char **argv)
+{
+    LauncherApplication app(argc, argv);
+
+    if (app.isRobotized()) {
         LauncherWindow* window = new LauncherWindow;
         QWebView* view = window->webView();
-        UrlLoader loader(view->page()->mainFrame(), listFile);
+        UrlLoader loader(view->page()->mainFrame(), app.urls().at(0));
         QObject::connect(view->page()->mainFrame(), SIGNAL(loadFinished(bool)), &loader, SLOT(loadNext()));
         loader.loadNext();
         window->show();
-        launcherMain(app);
-    } else {
-        LauncherWindow* window = 0;
-
-        // Look though the args for something we can open
-        for (int i = 1; i < args.count(); i++) {
-            if (!args.at(i).startsWith("-")) {
-                if (!window)
-                    window = new LauncherWindow(args.at(i));
-                else
-                    window->newWindow(args.at(i));
-            }
-        }
+        return launcherMain(app);
+    }
 
-        // If not, just open the default URL
-        if (!window)
-            window = new LauncherWindow(defaultUrl);
+    QStringList urls = app.urls();
 
-        window->show();
-        launcherMain(app);
+    if (urls.isEmpty()) {
+        QString defaultUrl = QString("file://%1/%2").arg(QDir::homePath()).arg(QLatin1String("index.html"));
+        if (QDir(defaultUrl).exists())
+            urls.append(defaultUrl);
+        else
+            urls.append("");
+    }
+
+    LauncherWindow* window = 0;
+    foreach (QString url, urls) {
+        if (!window)
+            window = new LauncherWindow(url);
+        else
+            window->newWindow(url);
     }
+
+    window->show();
+    return launcherMain(app);
 }
+
+#include "main.moc"

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list