21#include "qwebengineprofile.h"
29 QmlCookie *cookie = QmlStaticData::instance().getCookie(network_cookie);
31 map.insert(QSL(
"cookie"), QVariant::fromValue(cookie));
32 map.insert(QSL(
"removed"), false);
37 QmlCookie *cookie = QmlStaticData::instance().getCookie(network_cookie);
39 map.insert(QSL(
"cookie"), QVariant::fromValue(cookie));
40 map.insert(QSL(
"removed"), true);
45QNetworkCookie QmlCookies::getNetworkCookie(
const QVariantMap &map)
47 if (!map.contains(
QSL(
"name")) || !map.contains(
QSL(
"url"))) {
48 qWarning() <<
"Error:" <<
"Wrong arguments passed to" << __FUNCTION__;
49 return QNetworkCookie();
51 const QString name = map.value(
QSL(
"name")).toString();
52 const QString url = map.value(
QSL(
"url")).toString();
53 QVector<QNetworkCookie> cookies =
mApp->cookieJar()->getAllCookies();
54 for (
const QNetworkCookie &cookie : std::as_const(cookies)) {
55 if (QString::fromUtf8(cookie.name()) == name && cookie.domain() == url) {
59 return QNetworkCookie();
64 QNetworkCookie netCookie = getNetworkCookie(map);
70 QList<QObject*> qmlCookies;
71 const QString name = map.value(
QSL(
"name")).toString();
72 const QString url = map.value(
QSL(
"url")).toString();
73 const QString path = map.value(
QSL(
"path")).toString();
74 const bool secure = map.value(
QSL(
"secure")).toBool();
75 const bool session = map.value(
QSL(
"session")).toBool();
76 QVector<QNetworkCookie> cookies =
mApp->cookieJar()->getAllCookies();
77 for (
const QNetworkCookie &cookie : std::as_const(cookies)) {
78 if ((!map.contains(
QSL(
"name")) || QString::fromUtf8(cookie.name()) == name)
79 && (!map.contains(
QSL(
"url")) || cookie.domain() == url)
80 && (!map.contains(
QSL(
"path")) || cookie.path() == path)
81 && (!map.contains(
QSL(
"secure")) || cookie.isSecure() == secure)
82 && (!map.contains(
QSL(
"session")) || cookie.isSessionCookie() == session)) {
84 qmlCookies.append(qmlCookie);
92 const QString name = map.value(
QSL(
"name")).toString();
93 const QString url = map.value(
QSL(
"url")).toString();
94 const QString path = map.value(
QSL(
"path")).toString();
95 const bool secure = map.value(
QSL(
"secure")).toBool();
96 const QDateTime expirationDate = QDateTime::fromMSecsSinceEpoch(map.value(
QSL(
"expirationDate")).toDouble());
97 const bool httpOnly = map.value(
QSL(
"httpOnly")).toBool();
98 const QString
value = map.value(
QSL(
"value")).toString();
99 QNetworkCookie cookie;
100 cookie.setName(name.toUtf8());
101 cookie.setDomain(url);
102 cookie.setPath(path);
103 cookie.setSecure(secure);
104 cookie.setExpirationDate(expirationDate);
105 cookie.setHttpOnly(httpOnly);
106 cookie.setValue(
value.toUtf8());
107 mApp->webProfile()->cookieStore()->setCookie(cookie);
112 QNetworkCookie netCookie = getNetworkCookie(map);
113 mApp->webProfile()->cookieStore()->deleteCookie(netCookie);
void cookieAdded(const QNetworkCookie &cookie)
void cookieRemoved(const QNetworkCookie &cookie)
The class exposing QNetworkCookie to QML.
Q_INVOKABLE void set(const QVariantMap &map)
Set a cookie.
QmlCookies(QObject *parent=nullptr)
Q_INVOKABLE QList< QObject * > getAll(const QVariantMap &map)
Get all cookies matching a criteria.
Q_INVOKABLE void remove(const QVariantMap &map)
Remove a cookie.
Q_INVOKABLE QmlCookie * get(const QVariantMap &map)
Get a cookie.
QmlCookie * getCookie(const QNetworkCookie &cookie)
static QmlStaticData & instance()
int value(const QColor &c)