diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2009-03-05 14:34:32 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-03-05 14:34:32 -0800 |
commit | 635860845790a19bf50bbc51ba8fb66a96dde068 (patch) | |
tree | ef6ad9ff73a5b57f65249d4232a202fa77e6a140 /WebKit/qt/QtLauncher | |
parent | 8e35f3cfc7fba1d1c829dc557ebad6409cbe16a2 (diff) | |
download | external_webkit-635860845790a19bf50bbc51ba8fb66a96dde068.zip external_webkit-635860845790a19bf50bbc51ba8fb66a96dde068.tar.gz external_webkit-635860845790a19bf50bbc51ba8fb66a96dde068.tar.bz2 |
auto import from //depot/cupcake/@136594
Diffstat (limited to 'WebKit/qt/QtLauncher')
-rw-r--r-- | WebKit/qt/QtLauncher/main.cpp | 104 |
1 files changed, 95 insertions, 9 deletions
diff --git a/WebKit/qt/QtLauncher/main.cpp b/WebKit/qt/QtLauncher/main.cpp index 4d57e56..5d9fef6 100644 --- a/WebKit/qt/QtLauncher/main.cpp +++ b/WebKit/qt/QtLauncher/main.cpp @@ -42,6 +42,11 @@ #include <QtUiTools/QUiLoader> +#include <QVector> +#include <QTextStream> +#include <QFile> +#include <cstdio> + class WebPage : public QWebPage { public: @@ -83,10 +88,14 @@ public: } } - QWebPage *webPage() const { + QWebPage* webPage() const { return view->page(); } + QWebView* webView() const { + return view; + } + protected slots: void changeLocation() { @@ -165,7 +174,7 @@ protected slots: } void setEditable(bool on) { - view->page()->setEditable(on); + view->page()->setContentEditable(on); formatMenuAction->setVisible(on); } @@ -322,6 +331,69 @@ QObject *WebPage::createPlugin(const QString &classId, const QUrl &url, const QS return loader.createWidget(classId, view()); } +class URLLoader : public QObject +{ + Q_OBJECT +public: + URLLoader(QWebView* view, const QString& inputFileName) + : m_view(view) + , m_stdOut(stdout) + { + init(inputFileName); + } + +public slots: + void loadNext() + { + QString qstr; + if (getUrl(qstr)) { + QUrl url(qstr, QUrl::StrictMode); + if (url.isValid()) { + m_stdOut << "Loading " << qstr << " ......" << endl; + m_view->load(url); + } else + loadNext(); + } else + disconnect(m_view, 0, this, 0); + } + +private: + void init(const QString& inputFileName) + { + QFile inputFile(inputFileName); + if (inputFile.open(QIODevice::ReadOnly | QIODevice::Text)) { + QTextStream stream(&inputFile); + QString line; + while (true) { + line = stream.readLine(); + if (line.isNull()) + break; + m_urls.append(line); + } + } else { + qDebug() << "Cant't open list file"; + exit(0); + } + m_index = 0; + inputFile.close(); + } + + bool getUrl(QString& qstr) + { + if (m_index == m_urls.size()) + return false; + + qstr = m_urls[m_index++]; + return true; + } + +private: + QVector<QString> m_urls; + int m_index; + QWebView* m_view; + QTextStream m_stdOut; +}; + #include "main.moc" int main(int argc, char **argv) @@ -342,12 +414,26 @@ int main(int argc, char **argv) QWebSettings::globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true); const QStringList args = app.arguments(); - if (args.count() > 1) - url = args.at(1); - - MainWindow window(url); - window.show(); - return app.exec(); + // robotized + if (args.contains(QLatin1String("-r"))) { + QString listFile = args.at(2); + if (!(args.count() == 3) && QFile::exists(listFile)) { + qDebug() << "Usage: QtLauncher -r listfile"; + exit(0); + } + MainWindow window(url); + QWebView *view = window.webView(); + URLLoader loader(view, listFile); + QObject::connect(view, SIGNAL(loadFinished(bool)), &loader, SLOT(loadNext())); + window.show(); + return app.exec(); + } else { + if (args.count() > 1) + url = args.at(1); + + MainWindow window(url); + window.show(); + return app.exec(); + } } - |