summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorMichal Klocek <michal.klocek@theqtcompany.com>2015-12-02 11:37:46 +0100
committerMichal Klocek <michal.klocek@theqtcompany.com>2016-01-26 14:51:48 +0000
commit9490ae8570c950e8120e498fbdc459f5754df0bf (patch)
tree13b31b2d202051acc9f77e8f69e0ea90ffe00f90 /examples
parent7d453a0526fdc001b8af826756030cc571110403 (diff)
Add cookiebrowser example
A cookiebrowser shows collected cookies during browsing, users can view cookie content, delete and add new cookies. Change-Id: Ib9cdc29e7ca34c488dd249b44f9e32491517bd60 Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/examples.pro1
-rw-r--r--examples/webenginewidgets/cookiebrowser/cookiebrowser.pro19
-rw-r--r--examples/webenginewidgets/cookiebrowser/cookiebrowser.qrc5
-rw-r--r--examples/webenginewidgets/cookiebrowser/cookiedialog.ui189
-rw-r--r--examples/webenginewidgets/cookiebrowser/cookiewidget.ui92
-rw-r--r--examples/webenginewidgets/cookiebrowser/doc/images/cookiebrowser.pngbin0 -> 31643 bytes
-rw-r--r--examples/webenginewidgets/cookiebrowser/doc/src/cookiebrowser.qdoc41
-rw-r--r--examples/webenginewidgets/cookiebrowser/main.cpp52
-rw-r--r--examples/webenginewidgets/cookiebrowser/mainwindow.cpp192
-rw-r--r--examples/webenginewidgets/cookiebrowser/mainwindow.h96
-rw-r--r--examples/webenginewidgets/cookiebrowser/mainwindow.ui200
-rw-r--r--examples/webenginewidgets/cookiebrowser/view-refresh.pngbin0 -> 1364 bytes
12 files changed, 887 insertions, 0 deletions
diff --git a/examples/examples.pro b/examples/examples.pro
index fdd25664..867ce4cc 100644
--- a/examples/examples.pro
+++ b/examples/examples.pro
@@ -7,6 +7,7 @@ qtHaveModule(webengine) {
qtHaveModule(webenginewidgets) {
SUBDIRS += \
webenginewidgets/contentmanipulation \
+ webenginewidgets/cookiebrowser \
webenginewidgets/demobrowser \
webenginewidgets/markdowneditor
}
diff --git a/examples/webenginewidgets/cookiebrowser/cookiebrowser.pro b/examples/webenginewidgets/cookiebrowser/cookiebrowser.pro
new file mode 100644
index 00000000..66ea064e
--- /dev/null
+++ b/examples/webenginewidgets/cookiebrowser/cookiebrowser.pro
@@ -0,0 +1,19 @@
+QT += core gui webenginewidgets
+TARGET = cookiebrowser
+TEMPLATE = app
+CONFIG += c++11
+
+SOURCES += \
+ main.cpp\
+ mainwindow.cpp
+
+HEADERS += \
+ mainwindow.h
+
+FORMS += \
+ mainwindow.ui \
+ cookiedialog.ui \
+ cookiewidget.ui
+
+RESOURCES += \
+ cookiebrowser.qrc
diff --git a/examples/webenginewidgets/cookiebrowser/cookiebrowser.qrc b/examples/webenginewidgets/cookiebrowser/cookiebrowser.qrc
new file mode 100644
index 00000000..8805f2c5
--- /dev/null
+++ b/examples/webenginewidgets/cookiebrowser/cookiebrowser.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/">
+ <file>view-refresh.png</file>
+ </qresource>
+</RCC>
diff --git a/examples/webenginewidgets/cookiebrowser/cookiedialog.ui b/examples/webenginewidgets/cookiebrowser/cookiedialog.ui
new file mode 100644
index 00000000..ad6e5cab
--- /dev/null
+++ b/examples/webenginewidgets/cookiebrowser/cookiedialog.ui
@@ -0,0 +1,189 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>CookieDialog</class>
+ <widget class="QDialog" name="CookieDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>245</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Cookie</string>
+ </property>
+ <layout class="QFormLayout" name="formLayout">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Name</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLineEdit" name="m_nameLineEdit">
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>Domain</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QLineEdit" name="m_domainLineEdit">
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="0">
+ <widget class="QLabel" name="label_4">
+ <property name="text">
+ <string>Path</string>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="1">
+ <widget class="QLineEdit" name="m_pathLineEdit">
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="6" column="0">
+ <widget class="QLabel" name="label_5">
+ <property name="text">
+ <string>isHttpOnly</string>
+ </property>
+ </widget>
+ </item>
+ <item row="6" column="1">
+ <widget class="QComboBox" name="m_isHttpOnlyComboBox"/>
+ </item>
+ <item row="7" column="0">
+ <widget class="QLabel" name="label_3">
+ <property name="text">
+ <string>isSecure</string>
+ </property>
+ </widget>
+ </item>
+ <item row="8" column="1">
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="m_addButton">
+ <property name="enabled">
+ <bool>true</bool>
+ </property>
+ <property name="text">
+ <string>Add</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="m_cancelButton">
+ <property name="text">
+ <string>Cancel</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item row="7" column="1">
+ <widget class="QComboBox" name="m_isSecureComboBox"/>
+ </item>
+ <item row="3" column="0">
+ <widget class="QLabel" name="label_6">
+ <property name="text">
+ <string>Value</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1">
+ <widget class="QLineEdit" name="m_valueLineEdit">
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="1">
+ <widget class="QDateEdit" name="m_dateEdit">
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="0">
+ <widget class="QLabel" name="label_7">
+ <property name="text">
+ <string>Expires</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <tabstops>
+ <tabstop>m_nameLineEdit</tabstop>
+ <tabstop>m_domainLineEdit</tabstop>
+ <tabstop>m_valueLineEdit</tabstop>
+ <tabstop>m_dateEdit</tabstop>
+ <tabstop>m_pathLineEdit</tabstop>
+ <tabstop>m_isHttpOnlyComboBox</tabstop>
+ <tabstop>m_isSecureComboBox</tabstop>
+ <tabstop>m_addButton</tabstop>
+ <tabstop>m_cancelButton</tabstop>
+ </tabstops>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>m_cancelButton</sender>
+ <signal>clicked()</signal>
+ <receiver>CookieDialog</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>350</x>
+ <y>103</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>199</x>
+ <y>63</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>m_addButton</sender>
+ <signal>clicked()</signal>
+ <receiver>CookieDialog</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>265</x>
+ <y>112</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>199</x>
+ <y>63</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
diff --git a/examples/webenginewidgets/cookiebrowser/cookiewidget.ui b/examples/webenginewidgets/cookiebrowser/cookiewidget.ui
new file mode 100644
index 00000000..816d7473
--- /dev/null
+++ b/examples/webenginewidgets/cookiebrowser/cookiewidget.ui
@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>CookieWidget</class>
+ <widget class="QWidget" name="CookieWidget">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>300</width>
+ <height>71</height>
+ </rect>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>300</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="maximumSize">
+ <size>
+ <width>310</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout" stretch="3,1">
+ <item>
+ <layout class="QFormLayout" name="formLayout">
+ <property name="formAlignment">
+ <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
+ </property>
+ <item row="0" column="0">
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Name:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLabel" name="m_nameLabel">
+ <property name="text">
+ <string>Empty</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>Domain:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QLabel" name="m_domainLabel">
+ <property name="text">
+ <string>Emtpy</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QPushButton" name="m_viewButton">
+ <property name="text">
+ <string>View</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="m_deleteButton">
+ <property name="text">
+ <string>Delete</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/examples/webenginewidgets/cookiebrowser/doc/images/cookiebrowser.png b/examples/webenginewidgets/cookiebrowser/doc/images/cookiebrowser.png
new file mode 100644
index 00000000..4e76ba6d
--- /dev/null
+++ b/examples/webenginewidgets/cookiebrowser/doc/images/cookiebrowser.png
Binary files differ
diff --git a/examples/webenginewidgets/cookiebrowser/doc/src/cookiebrowser.qdoc b/examples/webenginewidgets/cookiebrowser/doc/src/cookiebrowser.qdoc
new file mode 100644
index 00000000..259de072
--- /dev/null
+++ b/examples/webenginewidgets/cookiebrowser/doc/src/cookiebrowser.qdoc
@@ -0,0 +1,41 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** 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 The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Free Documentation License Usage
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file. Please review the following information to ensure
+** the GNU Free Documentation License version 1.3 requirements
+** will be met: http://www.gnu.org/copyleft/fdl.html.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example webenginewidgets/cookiebrowser
+ \title WebEngine Cookie Browser Example
+ \ingroup webengine-widgetexamples
+ \brief A cookie browser based on Qt WebEngine Widgets
+
+ \image cookiebrowser.png
+
+ \e {Cookie Browser} demonstrates how to use the \l{Qt WebEngine Widgets C++ Classes}
+ {Qt WebEngine C++ classes} to manage cookies. The browser can be used to view cookie content as
+ well as delete cookies and add new cookies.
+
+ \include examples-run.qdocinc
+*/
diff --git a/examples/webenginewidgets/cookiebrowser/main.cpp b/examples/webenginewidgets/cookiebrowser/main.cpp
new file mode 100644
index 00000000..c122eb7c
--- /dev/null
+++ b/examples/webenginewidgets/cookiebrowser/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/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.
+**
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company 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$
+**
+****************************************************************************/
+
+#include "mainwindow.h"
+#include <QApplication>
+#include <QUrl>
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow window(QUrl("http://qt.io"));
+ window.show();
+ return app.exec();
+}
diff --git a/examples/webenginewidgets/cookiebrowser/mainwindow.cpp b/examples/webenginewidgets/cookiebrowser/mainwindow.cpp
new file mode 100644
index 00000000..4139153c
--- /dev/null
+++ b/examples/webenginewidgets/cookiebrowser/mainwindow.cpp
@@ -0,0 +1,192 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/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.
+**
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company 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$
+**
+****************************************************************************/
+
+#include "mainwindow.h"
+#include <QWebEngineCookieStore>
+#include <QWebEngineProfile>
+
+CookieDialog::CookieDialog(const QNetworkCookie &cookie, QWidget *parent): QDialog(parent)
+{
+ setupUi(this);
+ m_nameLineEdit->setText(cookie.name());
+ m_domainLineEdit->setText(cookie.domain());
+ m_valueLineEdit->setText(cookie.value());
+ m_pathLineEdit->setText(cookie.path());
+ m_dateEdit->setDate(cookie.expirationDate().date());
+ m_isSecureComboBox->addItem(cookie.isSecure() ? tr("yes") : tr("no"));
+ m_isHttpOnlyComboBox->addItem(cookie.isHttpOnly() ? tr("yes") : tr("no"));
+ m_addButton->setVisible(false);
+ m_cancelButton->setText(tr("Close"));
+}
+
+CookieDialog::CookieDialog(QWidget *parent): QDialog(parent)
+{
+ setupUi(this);
+ m_nameLineEdit->setReadOnly(false);
+ m_domainLineEdit->setReadOnly(false);
+ m_valueLineEdit->setReadOnly(false);
+ m_pathLineEdit->setReadOnly(false);
+ m_dateEdit->setReadOnly(false);
+ m_dateEdit->setDate(QDateTime::currentDateTime().addYears(1).date());
+ m_isSecureComboBox->addItem(tr("no"));
+ m_isSecureComboBox->addItem(tr("yes"));
+ m_isHttpOnlyComboBox->addItem(tr("no"));
+ m_isHttpOnlyComboBox->addItem(tr("yes"));
+}
+
+QNetworkCookie CookieDialog::cookie()
+{
+ QNetworkCookie cookie;
+ cookie.setDomain(m_domainLineEdit->text());
+ cookie.setName(m_nameLineEdit->text().toLatin1());
+ cookie.setValue(m_valueLineEdit->text().toLatin1());
+ cookie.setExpirationDate(QDateTime(m_dateEdit->date()));
+ cookie.setPath(m_pathLineEdit->text());
+ cookie.setSecure(m_isSecureComboBox->currentText() == tr("yes"));
+ cookie.setHttpOnly(m_isHttpOnlyComboBox->currentText() == tr("yes"));
+ return cookie;
+}
+
+CookieWidget::CookieWidget(const QNetworkCookie &cookie, QWidget *parent): QWidget(parent)
+{
+ setupUi(this);
+ setAutoFillBackground(true);
+ m_nameLabel->setText(cookie.name());
+ m_domainLabel->setText(cookie.domain());
+ connect(m_viewButton, &QPushButton::clicked, this, &CookieWidget::viewClicked);
+ connect(m_deleteButton, &QPushButton::clicked, this, &CookieWidget::deleteClicked);
+}
+
+void CookieWidget::setHighlighted(bool enabled)
+{
+ QPalette p = palette();
+ p.setColor(backgroundRole(), enabled ? QColor(0xF0, 0xF8, 0xFF) : Qt::white);
+ setPalette(p);
+}
+
+MainWindow::MainWindow(const QUrl &url) :
+ QMainWindow(),
+ m_store(nullptr),
+ m_layout(new QVBoxLayout)
+{
+ setupUi(this);
+ m_urlLineEdit->setText(url.toString());
+
+ m_layout->addItem(new QSpacerItem(0,0, QSizePolicy::Minimum, QSizePolicy::Expanding));
+ m_layout->setContentsMargins(0, 0, 0, 0);
+ m_layout->setSpacing(0);
+
+ QWidget *w = new QWidget();
+ QPalette p = w->palette();
+ p.setColor(widget->backgroundRole(), Qt::white);
+ w->setPalette(p);
+ w->setLayout(m_layout);
+
+ m_scrollArea->setWidget(w);
+ m_scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ m_scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
+
+ connect(m_urlButton, &QPushButton::clicked, this, &MainWindow::handleUrlClicked);
+ connect(m_deleteAllButton, &QPushButton::clicked, this, &MainWindow::handleDeleteAllClicked);
+ connect(m_newButton, &QPushButton::clicked, this, &MainWindow::handleNewClicked);
+
+ m_store = m_webview->page()->profile()->cookieStore();
+ connect(m_store, &QWebEngineCookieStore::cookieAdded, this, &MainWindow::handleCookieAdded);
+ m_store->loadAllCookies();
+ m_webview->load(url);
+}
+
+bool MainWindow::containsCookie(const QNetworkCookie &cookie)
+{
+ for (auto c: m_cookies) {
+ if (c.hasSameIdentifier(cookie))
+ return true;
+ }
+ return false;
+}
+
+void MainWindow::handleCookieAdded(const QNetworkCookie &cookie)
+{
+ // only new cookies
+ if (containsCookie(cookie))
+ return;
+
+ CookieWidget *widget = new CookieWidget(cookie);
+ widget->setHighlighted(m_cookies.count() % 2);
+ m_cookies.append(cookie);
+ m_layout->insertWidget(0,widget);
+
+ connect(widget, &CookieWidget::deleteClicked, [this, cookie, widget]() {
+ m_store->deleteCookie(cookie);
+ delete widget;
+ m_cookies.removeOne(cookie);
+ for (int i = 0; i < m_layout->count() - 1; i++) {
+ // fix background colors
+ auto widget = qobject_cast<CookieWidget*>(m_layout->itemAt(i)->widget());
+ widget->setHighlighted(i % 2);
+ }
+ });
+
+ connect(widget, &CookieWidget::viewClicked, [cookie]() {
+ CookieDialog dialog(cookie);
+ dialog.exec();
+ });
+}
+
+void MainWindow::handleDeleteAllClicked()
+{
+ m_store->deleteAllCookies();
+ for (int i = m_layout->count() - 1; i >= 0; i--)
+ delete m_layout->itemAt(i)->widget();
+ m_cookies.clear();
+}
+
+void MainWindow::handleNewClicked()
+{
+ CookieDialog dialog;
+ if (dialog.exec() == QDialog::Accepted)
+ m_store->setCookie(dialog.cookie());
+}
+
+void MainWindow::handleUrlClicked()
+{
+ m_webview->load(QUrl(m_urlLineEdit->text()));
+}
diff --git a/examples/webenginewidgets/cookiebrowser/mainwindow.h b/examples/webenginewidgets/cookiebrowser/mainwindow.h
new file mode 100644
index 00000000..93d0a5a3
--- /dev/null
+++ b/examples/webenginewidgets/cookiebrowser/mainwindow.h
@@ -0,0 +1,96 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/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.
+**
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company 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 MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include "ui_mainwindow.h"
+#include "ui_cookiewidget.h"
+#include "ui_cookiedialog.h"
+#include <QNetworkCookie>
+#include <QMainWindow>
+
+QT_BEGIN_NAMESPACE
+class QWebEngineCookieStore;
+QT_END_NAMESPACE
+
+class CookieDialog : public QDialog, public Ui_CookieDialog
+{
+ Q_OBJECT
+public:
+ CookieDialog(const QNetworkCookie &cookie, QWidget *parent = nullptr);
+ CookieDialog(QWidget *parent = 0);
+ QNetworkCookie cookie();
+};
+
+class CookieWidget : public QWidget, public Ui_CookieWidget
+{
+ Q_OBJECT
+public:
+ CookieWidget(const QNetworkCookie &cookie, QWidget *parent = nullptr);
+ void setHighlighted(bool enabled);
+signals:
+ void deleteClicked();
+ void viewClicked();
+};
+
+class MainWindow : public QMainWindow, public Ui_MainWindow
+{
+ Q_OBJECT
+public:
+ explicit MainWindow(const QUrl &url);
+
+private:
+ bool containsCookie(const QNetworkCookie &cookie);
+
+private slots:
+ void handleCookieAdded(const QNetworkCookie &cookie);
+ void handleDeleteAllClicked();
+ void handleNewClicked();
+ void handleUrlClicked();
+
+private:
+ QWebEngineCookieStore *m_store;
+ QVector<QNetworkCookie> m_cookies;
+ QVBoxLayout *m_layout;
+};
+
+#endif // MAINWINDOW_H
diff --git a/examples/webenginewidgets/cookiebrowser/mainwindow.ui b/examples/webenginewidgets/cookiebrowser/mainwindow.ui
new file mode 100644
index 00000000..78d45139
--- /dev/null
+++ b/examples/webenginewidgets/cookiebrowser/mainwindow.ui
@@ -0,0 +1,200 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>1400</width>
+ <height>650</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Cookie Manager</string>
+ </property>
+ <widget class="QWidget" name="centralWidget">
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <item>
+ <widget class="QFrame" name="frame">
+ <property name="frameShape">
+ <enum>QFrame::StyledPanel</enum>
+ </property>
+ <property name="frameShadow">
+ <enum>QFrame::Raised</enum>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QWidget" name="widget" native="true">
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QLineEdit" name="m_urlLineEdit"/>
+ </item>
+ <item>
+ <widget class="QPushButton" name="m_urlButton">
+ <property name="text">
+ <string/>
+ </property>
+ <property name="icon">
+ <iconset resource="cookiebrowser.qrc">
+ <normaloff>:/view-refresh.png</normaloff>:/view-refresh.png</iconset>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QWebEngineView" name="m_webview" native="true">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>0</width>
+ <height>0</height>
+ </size>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QFrame" name="frame_2">
+ <property name="maximumSize">
+ <size>
+ <width>336</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="frameShape">
+ <enum>QFrame::StyledPanel</enum>
+ </property>
+ <property name="frameShadow">
+ <enum>QFrame::Raised</enum>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <widget class="QWidget" name="widget_2" native="true">
+ <layout class="QHBoxLayout" name="horizontalLayout_3">
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Cookies:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>87</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="m_newButton">
+ <property name="text">
+ <string>New</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="m_deleteAllButton">
+ <property name="text">
+ <string>Delete All</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QScrollArea" name="m_scrollArea">
+ <property name="minimumSize">
+ <size>
+ <width>320</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="maximumSize">
+ <size>
+ <width>320</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="widgetResizable">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <customwidgets>
+ <customwidget>
+ <class>QWebEngineView</class>
+ <extends>QWidget</extends>
+ <header>qwebengineview.h</header>
+ <container>1</container>
+ </customwidget>
+ </customwidgets>
+ <resources>
+ <include location="cookiebrowser.qrc"/>
+ </resources>
+ <connections>
+ <connection>
+ <sender>m_urlLineEdit</sender>
+ <signal>returnPressed()</signal>
+ <receiver>m_urlButton</receiver>
+ <slot>click()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>509</x>
+ <y>28</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>1024</x>
+ <y>27</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
diff --git a/examples/webenginewidgets/cookiebrowser/view-refresh.png b/examples/webenginewidgets/cookiebrowser/view-refresh.png
new file mode 100644
index 00000000..cab4d02c
--- /dev/null
+++ b/examples/webenginewidgets/cookiebrowser/view-refresh.png
Binary files differ