diff --git a/examples/common.pri b/examples/common.pri index b85159ce82025f670d5f97fa7ac5ff98579429fc..4a1b676f298c421c011c7ebd6245966f96a96847 100644 --- a/examples/common.pri +++ b/examples/common.pri @@ -1,7 +1,10 @@ -INCLUDEPATH += $$absolute_path(../lib, $$PWD) +INCLUDEPATH += $$absolute_path(../lib, $$PWD) \ + $$absolute_path(common, $$PWD) LIBPATH = $$getOutDir()/$$getConfigDir()/lib +HEADERS += common/util.h + LIBS += -L$$LIBPATH -lQt5WebEngine QMAKE_RPATHDIR += $$LIBPATH diff --git a/examples/common/util.h b/examples/common/util.h new file mode 100644 index 0000000000000000000000000000000000000000..7db6e2cd5b3478b7612787fc3909e47f0a74fc9e --- /dev/null +++ b/examples/common/util.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef UTIL_H +#define UTIL_H + +#include <QtCore/QCoreApplication> +#include <QtCore/QFileInfo> +#include <QtCore/QUrl> + +QUrl urlFromUserInput(const QString& userInput) +{ + QFileInfo fileInfo(userInput); + if (fileInfo.exists()) + return QUrl(fileInfo.absoluteFilePath()); + return QUrl::fromUserInput(userInput); +} + +QUrl startupUrl() +{ + QUrl ret; + QStringList args(qApp->arguments()); + args.takeFirst(); + Q_FOREACH(const QString& arg, args) { + if (arg.startsWith(QLatin1Char('-'))) + continue; + ret = urlFromUserInput(arg); + if (ret.isValid()) + return ret; + } + return QUrl(QStringLiteral("http://qt-project.org/")); +} + + +#endif // UTIL_H diff --git a/examples/qtquick/quickwindow.cpp b/examples/qtquick/quickwindow.cpp index 6dd11cc11e06a2a4cb7a4d06aee43f8261388502..1f753c691dfd83d20ec2f8f60e1fd976b8455c2f 100644 --- a/examples/qtquick/quickwindow.cpp +++ b/examples/qtquick/quickwindow.cpp @@ -41,6 +41,8 @@ #include "quickwindow.h" +#include "util.h" + #include <QFileInfo> #include <QObject> #include <QQmlContext> @@ -51,13 +53,8 @@ class Utils : public QObject { Q_OBJECT public: Utils(QObject* parent = 0) : QObject(parent) { } - Q_INVOKABLE static QUrl fromUserInput(const QString& userInput) - { - QFileInfo fileInfo(userInput); - if (fileInfo.exists()) - return QUrl(fileInfo.absoluteFilePath()); - return QUrl::fromUserInput(userInput); - } + Q_INVOKABLE static QUrl fromUserInput(const QString& userInput) { return urlFromUserInput(userInput); } + Q_INVOKABLE static QUrl initialUrl() { return startupUrl(); } }; #include "quickwindow.moc" diff --git a/examples/qtquick/quickwindow.qml b/examples/qtquick/quickwindow.qml index 7d42b2c0172420a409ff266d2a9160b339db08ee..7962be141eed3dedd06fe2194e05a18c39f926f2 100644 --- a/examples/qtquick/quickwindow.qml +++ b/examples/qtquick/quickwindow.qml @@ -47,7 +47,7 @@ ApplicationWindow { id: webContentsView focus: true anchors.fill: parent - url: "http://qt-project.org/" + url: utils.initialUrl() onUrlChanged: addressBar.text = url } diff --git a/examples/widgets/widgetwindow.cpp b/examples/widgets/widgetwindow.cpp index dad64cb7fbce61585a8778546180e818f2401fe1..589ef13c36c535c1f913672e42142b839444c32b 100644 --- a/examples/widgets/widgetwindow.cpp +++ b/examples/widgets/widgetwindow.cpp @@ -42,6 +42,7 @@ #include "widgetwindow.h" #include "qwebcontentsview.h" +#include "util.h" static const int margin = 1; @@ -91,7 +92,7 @@ WidgetWindow::WidgetWindow() connect(m_webView.data(), SIGNAL(titleChanged(const QString&)), SLOT(setWindowTitle(const QString&))); connect(m_webView.data(), SIGNAL(urlChanged(const QUrl&)), SLOT(setAddressBarUrl(const QUrl&))); - m_webView->load(QUrl(QStringLiteral("http://qt-project.org/"))); + m_webView->load(startupUrl()); } WidgetWindow::~WidgetWindow() @@ -115,5 +116,6 @@ void WidgetWindow::loadStarted() void WidgetWindow::loadFinished(bool success) { + Q_UNUSED(success); reloadButton->setIcon(QIcon::fromTheme("view-refresh")); }