From 480cbb2b00b80baa90676fb3adfa982711006da8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Br=C3=BCning?= Date: Mon, 7 Apr 2014 14:52:26 +0200 Subject: Fix up tabbed browser example. * Replaces deprecated Q_WS_MAC preprocessor defines. * Adds a command line parser. * Adds Digia Qt home page to the default bookmarks. * Removes dead Q_WS_QWS flagged code. Task-number: QTBUG-38069 Change-Id: If4ef67434c76c2ea096fa1250a9ffaa0e53e47dd Reviewed-by: Allan Sandfeld Jensen --- .../webkitwidgets/browser/browserapplication.cpp | 76 ++++++++++++++++------ .../webkitwidgets/browser/browserapplication.h | 12 ++-- .../webkitwidgets/browser/browsermainwindow.cpp | 10 +-- .../browser/data/defaultbookmarks.xbel | 6 +- examples/webkitwidgets/browser/main.cpp | 2 +- 5 files changed, 72 insertions(+), 34 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 +#include #include #include #include @@ -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 << ""; + if (!errorMessage.isEmpty()) + str << errorMessage; + str << "
" << parser.helpText() << "
"; + 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("

Invalid argument

")); + return; + } + + QStringList args = commandLineParser.positionalArguments(); + if (args.count() > 1) { + showHelp(commandLineParser, QStringLiteral("

Too many arguments.

")); + return; + } else if (args.count() == 1) { + m_initialUrl = args.at(0); + } + if (!m_initialUrl.isEmpty() && !QUrl::fromUserInput(m_initialUrl).isValid()) { + showHelp(commandLineParser, QString("

%1 is not a valid url

").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(QCoreApplication::instance())); } -#if defined(Q_WS_MAC) +#if defined(Q_OS_OSX) #include 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 -#include #include +#include #include @@ -70,6 +70,7 @@ public: void loadSettings(); bool isTheOnlyBrowser() const; + bool isCorrectlyInitialized() const; BrowserMainWindow *mainWindow(); QList 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 > 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 @@ WebKit.org + + Digia Qt Home Page + Qt Documentation - - Qt Quarterly - Qt Blog 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(); -- cgit v1.2.1 From 5f0fbc683bce200b17fea82eb711d8ad4c2f3f23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Br=C3=BCning?= Date: Mon, 7 Apr 2014 14:06:26 +0200 Subject: Fix up Fancy Browser example. * Prevent leaking of MainWindow. * Use proper command line argument parsing. * Make the Qt project page the default page. Task-number: QTBUG-38069 Change-Id: I6142ca207e659e47136e47e4d5817dfa617677e8 Reviewed-by: Allan Sandfeld Jensen --- examples/webkitwidgets/fancybrowser/main.cpp | 42 ++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 6 deletions(-) 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 #include "mainwindow.h" +static void showHelp(QCommandLineParser &parser, const QString errorMessage = QString()) +{ + QString text; + QTextStream str(&text); + str << ""; + if (!errorMessage.isEmpty()) + str << "

" << errorMessage << "

"; + str << "
" << parser.helpText() << "
"; + 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(); } -- cgit v1.2.1 From 184bfa548351bc82a74fc9323988a4a060fba738 Mon Sep 17 00:00:00 2001 From: Sergio Ahumada Date: Thu, 17 Apr 2014 17:33:51 +0200 Subject: Bump MODULE_VERSION to 5.3.1 Change-Id: Ie7b295760ee91612fa741e1a95323fce2db6e0a7 Reviewed-by: Oswald Buddenhagen --- .qmake.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.qmake.conf b/.qmake.conf index efd0e68..ef45a00 100644 --- a/.qmake.conf +++ b/.qmake.conf @@ -1,4 +1,4 @@ load(qt_build_config) CONFIG += qt_example_installs -MODULE_VERSION = 5.3.0 +MODULE_VERSION = 5.3.1 -- cgit v1.2.1