summaryrefslogtreecommitdiffstats
path: root/WebKitTools/QtLauncher/main.cpp
diff options
context:
space:
mode:
authorSteve Block <steveblock@google.com>2010-02-05 14:27:46 +0000
committerSteve Block <steveblock@google.com>2010-02-15 10:49:50 +0000
commit5e2bc6953fe6923165b8a5d7679939693a1d58d6 (patch)
tree6ccb8c24bc2bf5e8f413e6cfae250b729b426631 /WebKitTools/QtLauncher/main.cpp
parent4a00f4fccc3cb7e9996749a05631f5d7b9de756e (diff)
downloadexternal_webkit-5e2bc6953fe6923165b8a5d7679939693a1d58d6.zip
external_webkit-5e2bc6953fe6923165b8a5d7679939693a1d58d6.tar.gz
external_webkit-5e2bc6953fe6923165b8a5d7679939693a1d58d6.tar.bz2
Merge webkit.org at r54340 : Initial merge by git
Change-Id: Ib489d2ff91186ea3652522e1d586e54416a2cf44
Diffstat (limited to 'WebKitTools/QtLauncher/main.cpp')
-rw-r--r--WebKitTools/QtLauncher/main.cpp197
1 files changed, 160 insertions, 37 deletions
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"