Commit 74c4818d authored by kenneth@webkit.org's avatar kenneth@webkit.org

[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: svn://svn.chromium.org/blink/trunk@54297 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 8bdcfdb3
2010-02-03 Kenneth Rohde Christiansen <kenneth@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@webkit.org> 2010-02-03 Csaba Osztrogonác <ossy@webkit.org>
Rubber-stamped by Ariya Hidayat. Rubber-stamped by Ariya Hidayat.
......
...@@ -525,8 +525,6 @@ QObject* WebPage::createPlugin(const QString &classId, const QUrl&, const QStrin ...@@ -525,8 +525,6 @@ QObject* WebPage::createPlugin(const QString &classId, const QUrl&, const QStrin
} }
#include "main.moc"
int launcherMain(const QApplication& app) int launcherMain(const QApplication& app)
{ {
#ifndef NDEBUG #ifndef NDEBUG
...@@ -539,60 +537,185 @@ int launcherMain(const QApplication& app) ...@@ -539,60 +537,185 @@ int launcherMain(const QApplication& app)
#endif #endif
} }
int main(int argc, char **argv) class LauncherApplication : public QApplication {
{ Q_OBJECT
QApplication app(argc, argv);
QString defaultUrl = QString("file://%1/%2").arg(QDir::homePath()).arg(QLatin1String("index.html"));
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"); QList<QString> enumToKeys(const QMetaObject o, const QString& name, const QString& strip);
app.setApplicationVersion("0.1"); 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::setObjectCacheCapacities((16*1024*1024) / 8, (16*1024*1024) / 8, 16*1024*1024);
QWebSettings::globalSettings()->setAttribute(QWebSettings::PluginsEnabled, true); QWebSettings::globalSettings()->setAttribute(QWebSettings::PluginsEnabled, true);
QWebSettings::globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true); QWebSettings::globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
QWebSettings::enablePersistentStorage(); QWebSettings::enablePersistentStorage();
}
LauncherApplication::LauncherApplication(int& argc, char** argv)
: QApplication(argc, argv)
, m_isRobotized(false)
{
// To allow QWebInspector's configuration persistence // To allow QWebInspector's configuration persistence
QCoreApplication::setOrganizationName("Nokia"); setOrganizationName("Nokia");
QCoreApplication::setApplicationName("QtLauncher"); setApplicationName("QtLauncher");
setApplicationVersion("0.1");
const QStringList args = app.arguments(); applyDefaultSettings();
if (args.contains(QLatin1String("-r"))) { handleUserOptions();
// robotized }
QString listFile = args.at(2);
if (!(args.count() == 3) && QFile::exists(listFile)) { QString LauncherApplication::formatKeys(QList<QString> keys)
qDebug() << "Usage: QtLauncher -r listfile"; {
exit(0); 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; LauncherWindow* window = new LauncherWindow;
QWebView* view = window->webView(); 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())); QObject::connect(view->page()->mainFrame(), SIGNAL(loadFinished(bool)), &loader, SLOT(loadNext()));
loader.loadNext(); loader.loadNext();
window->show(); window->show();
launcherMain(app); return 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));
}
}
// If not, just open the default URL QStringList urls = app.urls();
if (!window)
window = new LauncherWindow(defaultUrl);
window->show(); if (urls.isEmpty()) {
launcherMain(app); 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"
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