summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorJani Heikkinen <jani.heikkinen@digia.com>2014-04-23 12:47:05 +0300
committerJani Heikkinen <jani.heikkinen@digia.com>2014-04-23 12:47:06 +0300
commitbce5056b9e16a943357e362455a46685d3f22093 (patch)
tree73c4e6413605ede3edb556e929a13cb1cdf9e362 /examples
parent184bfa548351bc82a74fc9323988a4a060fba738 (diff)
parent5f0fbc683bce200b17fea82eb711d8ad4c2f3f23 (diff)
downloadqtwebkit-examples-5.3.1.tar.gz
Merge remote-tracking branch 'origin/release' into stablev5.3.1stable5.3.1
Change-Id: Ic2230a86eb0dda83681f3d400367564ad7b594ad
Diffstat (limited to 'examples')
-rw-r--r--examples/webkitwidgets/browser/browserapplication.cpp76
-rw-r--r--examples/webkitwidgets/browser/browserapplication.h12
-rw-r--r--examples/webkitwidgets/browser/browsermainwindow.cpp10
-rw-r--r--examples/webkitwidgets/browser/data/defaultbookmarks.xbel6
-rw-r--r--examples/webkitwidgets/browser/main.cpp2
-rw-r--r--examples/webkitwidgets/fancybrowser/main.cpp42
6 files changed, 108 insertions, 40 deletions
diff --git a/examples/webkitwidgets/browser/browserapplication.cpp b/examples/webkitwidgets/browser/browserapplication.cpp
index 0e281de..0ea0027 100644
--- a/examples/webkitwidgets/browser/browserapplication.cpp
+++ b/examples/webkitwidgets/browser/browserapplication.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the demonstration applications of the Qt Toolkit.
@@ -51,6 +51,7 @@
#include "webview.h"
#include <QtCore/QBuffer>
+#include <QtCore/QCommandLineParser>
#include <QtCore/QDir>
#include <QtCore/QLibraryInfo>
#include <QtCore/QSettings>
@@ -75,36 +76,65 @@ HistoryManager *BrowserApplication::s_historyManager = 0;
NetworkAccessManager *BrowserApplication::s_networkAccessManager = 0;
BookmarksManager *BrowserApplication::s_bookmarksManager = 0;
+static void showHelp(QCommandLineParser &parser, const QString errorMessage = QString())
+{
+ QString text;
+ QTextStream str(&text);
+ str << "<html><head/><body>";
+ if (!errorMessage.isEmpty())
+ str << errorMessage;
+ str << "<pre>" << parser.helpText() << "</pre></body></html>";
+ QMessageBox box(errorMessage.isEmpty() ? QMessageBox::Information : QMessageBox::Warning,
+ QGuiApplication::applicationDisplayName(), text, QMessageBox::Ok);
+ box.setTextInteractionFlags(Qt::TextBrowserInteraction);
+ box.exec();
+}
+
BrowserApplication::BrowserApplication(int &argc, char **argv)
: QApplication(argc, argv)
, m_localServer(0)
+ , m_initialUrl(QString())
+ , m_correctlyInitialized(false)
{
QCoreApplication::setOrganizationName(QLatin1String("Qt"));
QCoreApplication::setApplicationName(QLatin1String("demobrowser"));
QCoreApplication::setApplicationVersion(QLatin1String("0.1"));
-#ifdef Q_WS_QWS
- // Use a different server name for QWS so we can run an X11
- // browser and a QWS browser in parallel on the same machine for
- // debugging
- QString serverName = QCoreApplication::applicationName() + QLatin1String("_qws");
-#else
+
+ QCommandLineParser commandLineParser;
+ commandLineParser.addPositionalArgument(QStringLiteral("url"),
+ QStringLiteral("The url to be loaded in the browser window."));
+
+ if (!commandLineParser.parse(QCoreApplication::arguments())) {
+ showHelp(commandLineParser, QStringLiteral("<p>Invalid argument</p>"));
+ return;
+ }
+
+ QStringList args = commandLineParser.positionalArguments();
+ if (args.count() > 1) {
+ showHelp(commandLineParser, QStringLiteral("<p>Too many arguments.</p>"));
+ return;
+ } else if (args.count() == 1) {
+ m_initialUrl = args.at(0);
+ }
+ if (!m_initialUrl.isEmpty() && !QUrl::fromUserInput(m_initialUrl).isValid()) {
+ showHelp(commandLineParser, QString("<p>%1 is not a valid url</p>").arg(m_initialUrl));
+ return;
+ }
+
+ m_correctlyInitialized = true;
+
QString serverName = QCoreApplication::applicationName();
-#endif
QLocalSocket socket;
socket.connectToServer(serverName);
if (socket.waitForConnected(500)) {
QTextStream stream(&socket);
- QStringList args = QCoreApplication::arguments();
- if (args.count() > 1)
- stream << args.last();
- else
- stream << QString();
+ stream << m_initialUrl;
stream.flush();
socket.waitForBytesWritten();
return;
}
-#if defined(Q_WS_MAC)
+#if defined(Q_OS_OSX)
QApplication::setQuitOnLastWindowClosed(false);
#else
QApplication::setQuitOnLastWindowClosed(true);
@@ -138,7 +168,7 @@ BrowserApplication::BrowserApplication(int &argc, char **argv)
m_lastSession = settings.value(QLatin1String("lastSession")).toByteArray();
settings.endGroup();
-#if defined(Q_WS_MAC)
+#if defined(Q_OS_OSX)
connect(this, SIGNAL(lastWindowClosed()),
this, SLOT(lastWindowClosed()));
#endif
@@ -157,7 +187,7 @@ BrowserApplication::~BrowserApplication()
delete s_bookmarksManager;
}
-#if defined(Q_WS_MAC)
+#if defined(Q_OS_OSX)
void BrowserApplication::lastWindowClosed()
{
clean();
@@ -172,7 +202,7 @@ BrowserApplication *BrowserApplication::instance()
return (static_cast<BrowserApplication *>(QCoreApplication::instance()));
}
-#if defined(Q_WS_MAC)
+#if defined(Q_OS_OSX)
#include <QtWidgets/QMessageBox>
void BrowserApplication::quitBrowser()
{
@@ -213,9 +243,8 @@ void BrowserApplication::postLaunch()
// newMainWindow() needs to be called in main() for this to happen
if (m_mainWindows.count() > 0) {
- QStringList args = QCoreApplication::arguments();
- if (args.count() > 1)
- mainWindow()->loadPage(args.last());
+ if (!m_initialUrl.isEmpty())
+ mainWindow()->loadPage(m_initialUrl);
else
mainWindow()->slotHome();
}
@@ -329,6 +358,11 @@ bool BrowserApplication::isTheOnlyBrowser() const
return (m_localServer != 0);
}
+bool BrowserApplication::isCorrectlyInitialized() const
+{
+ return m_correctlyInitialized;
+}
+
void BrowserApplication::installTranslator(const QString &name)
{
QTranslator *translator = new QTranslator(this);
@@ -336,7 +370,7 @@ void BrowserApplication::installTranslator(const QString &name)
QApplication::installTranslator(translator);
}
-#if defined(Q_WS_MAC)
+#if defined(Q_OS_OSX)
bool BrowserApplication::event(QEvent* event)
{
switch (event->type()) {
diff --git a/examples/webkitwidgets/browser/browserapplication.h b/examples/webkitwidgets/browser/browserapplication.h
index d4b89aa..7aac840 100644
--- a/examples/webkitwidgets/browser/browserapplication.h
+++ b/examples/webkitwidgets/browser/browserapplication.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the demonstration applications of the Qt Toolkit.
@@ -44,8 +44,8 @@
#include <QtWidgets/QApplication>
-#include <QtCore/QUrl>
#include <QtCore/QPointer>
+#include <QtCore/QUrl>
#include <QtGui/QIcon>
@@ -70,6 +70,7 @@ public:
void loadSettings();
bool isTheOnlyBrowser() const;
+ bool isCorrectlyInitialized() const;
BrowserMainWindow *mainWindow();
QList<BrowserMainWindow*> mainWindows();
QIcon icon(const QUrl &url) const;
@@ -83,14 +84,14 @@ public:
static NetworkAccessManager *networkAccessManager();
static BookmarksManager *bookmarksManager();
-#if defined(Q_WS_MAC)
+#if defined(Q_OS_OSX)
bool event(QEvent *event);
#endif
public slots:
BrowserMainWindow *newMainWindow();
void restoreLastSession();
-#if defined(Q_WS_MAC)
+#if defined(Q_OS_OSX)
void lastWindowClosed();
void quitBrowser();
#endif
@@ -112,6 +113,9 @@ private:
QList<QPointer<BrowserMainWindow> > m_mainWindows;
QLocalServer *m_localServer;
QByteArray m_lastSession;
+ QString m_initialUrl;
+ bool m_correctlyInitialized;
+
mutable QIcon m_defaultIcon;
};
diff --git a/examples/webkitwidgets/browser/browsermainwindow.cpp b/examples/webkitwidgets/browser/browsermainwindow.cpp
index b94cb25..de988ed 100644
--- a/examples/webkitwidgets/browser/browsermainwindow.cpp
+++ b/examples/webkitwidgets/browser/browsermainwindow.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the demonstration applications of the Qt Toolkit.
@@ -98,7 +98,7 @@ BrowserMainWindow::BrowserMainWindow(QWidget *parent, Qt::WindowFlags flags)
QVBoxLayout *layout = new QVBoxLayout;
layout->setSpacing(0);
layout->setMargin(0);
-#if defined(Q_WS_MAC)
+#if defined(Q_OS_OSX)
layout->addWidget(m_bookmarksToolbar);
layout->addWidget(new QWidget); // <- OS X tab widget style bug
#else
@@ -133,7 +133,7 @@ BrowserMainWindow::BrowserMainWindow(QWidget *parent, Qt::WindowFlags flags)
m_navigationBar, SLOT(setVisible(bool)));
connect(m_tabWidget, SIGNAL(toolBarVisibilityChangeRequested(bool)),
m_bookmarksToolbar, SLOT(setVisible(bool)));
-#if defined(Q_WS_MAC)
+#if defined(Q_OS_OSX)
connect(m_tabWidget, SIGNAL(lastTabClosed()),
this, SLOT(close()));
#else
@@ -278,7 +278,7 @@ void BrowserMainWindow::setupMenu()
action->setCheckable(true);
fileMenu->addSeparator();
-#if defined(Q_WS_MAC)
+#if defined(Q_OS_OSX)
fileMenu->addAction(tr("&Quit"), BrowserApplication::instance(), SLOT(quitBrowser()), QKeySequence(Qt::CTRL | Qt::Key_Q));
#else
fileMenu->addAction(tr("&Quit"), this, SLOT(close()), QKeySequence(Qt::CTRL | Qt::Key_Q));
@@ -591,7 +591,7 @@ void BrowserMainWindow::slotUpdateWindowTitle(const QString &title)
if (title.isEmpty()) {
setWindowTitle(tr("Qt Demo Browser"));
} else {
-#if defined(Q_WS_MAC)
+#if defined(Q_OS_OSX)
setWindowTitle(title);
#else
setWindowTitle(tr("%1 - Qt Demo Browser", "Page title and Browser name").arg(title));
diff --git a/examples/webkitwidgets/browser/data/defaultbookmarks.xbel b/examples/webkitwidgets/browser/data/defaultbookmarks.xbel
index 7a95e36..a616c76 100644
--- a/examples/webkitwidgets/browser/data/defaultbookmarks.xbel
+++ b/examples/webkitwidgets/browser/data/defaultbookmarks.xbel
@@ -9,12 +9,12 @@
<bookmark href="http://webkit.org/">
<title>WebKit.org</title>
</bookmark>
+ <bookmark href="http://qt.digia.com">
+ <title>Digia Qt Home Page</title>
+ </bookmark>
<bookmark href="http://qt-project.org/doc/">
<title>Qt Documentation</title>
</bookmark>
- <bookmark href="http://qt-project.org/quarterly/">
- <title>Qt Quarterly</title>
- </bookmark>
<bookmark href="http://planet.qt-project.org/">
<title>Qt Blog</title>
</bookmark>
diff --git a/examples/webkitwidgets/browser/main.cpp b/examples/webkitwidgets/browser/main.cpp
index ae54456..fac3d01 100644
--- a/examples/webkitwidgets/browser/main.cpp
+++ b/examples/webkitwidgets/browser/main.cpp
@@ -45,7 +45,7 @@ int main(int argc, char **argv)
{
Q_INIT_RESOURCE(data);
BrowserApplication application(argc, argv);
- if (!application.isTheOnlyBrowser())
+ if (!application.isTheOnlyBrowser() || !application.isCorrectlyInitialized())
return 0;
application.newMainWindow();
return application.exec();
diff --git a/examples/webkitwidgets/fancybrowser/main.cpp b/examples/webkitwidgets/fancybrowser/main.cpp
index 451f247..bde31b0 100644
--- a/examples/webkitwidgets/fancybrowser/main.cpp
+++ b/examples/webkitwidgets/fancybrowser/main.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the examples of the Qt Toolkit.
@@ -41,15 +41,45 @@
#include <QtWidgets>
#include "mainwindow.h"
+static void showHelp(QCommandLineParser &parser, const QString errorMessage = QString())
+{
+ QString text;
+ QTextStream str(&text);
+ str << "<html><head/><body>";
+ if (!errorMessage.isEmpty())
+ str << "<p>" << errorMessage << "</p>";
+ str << "<pre>" << parser.helpText() << "</pre></body></html>";
+ QMessageBox box(errorMessage.isEmpty() ? QMessageBox::Information : QMessageBox::Warning,
+ QGuiApplication::applicationDisplayName(), text, QMessageBox::Ok);
+ box.setTextInteractionFlags(Qt::TextBrowserInteraction);
+ box.exec();
+}
+
int main(int argc, char * argv[])
{
QApplication app(argc, argv);
+
+ QCommandLineParser commandLineParser;
+ commandLineParser.addPositionalArgument(QStringLiteral("url"),
+ QStringLiteral("The url to be loaded in the browser window."));
+ commandLineParser.process(app);
+ QStringList positionalArguments = commandLineParser.positionalArguments();
+
QUrl url;
- if (argc > 1)
- url = QUrl::fromUserInput(argv[1]);
+ if (positionalArguments.size() > 1) {
+ showHelp(commandLineParser, QStringLiteral("Too many arguments."));
+ return -1;
+ } else if (positionalArguments.size() == 1)
+ url = QUrl::fromUserInput(positionalArguments.at(0));
else
- url = QUrl("http://www.google.com/ncr");
- MainWindow *browser = new MainWindow(url);
- browser->show();
+ url = QUrl("http://www.qt-project.org");
+
+ if (!url.isValid()) {
+ showHelp(commandLineParser, QString("%1 is not a valid url.").arg(positionalArguments.at(0)));
+ return -1;
+ }
+
+ MainWindow browser(url);
+ browser.show();
return app.exec();
}