1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00

fixed caching in qml cookies

This commit is contained in:
Anmol Gautam 2018-08-03 11:37:03 +05:30
parent a2440585d8
commit caec5838b9
2 changed files with 9 additions and 10 deletions

View File

@ -95,8 +95,9 @@ QmlCookie *QmlCookieData::get(QNetworkCookie *cookie)
{
QmlCookie *qmlCookie = m_cookies.value(cookie);
if (!qmlCookie) {
qmlCookie = new QmlCookie(cookie);
m_cookies.insert(cookie, qmlCookie);
QNetworkCookie *netCookie = new QNetworkCookie(*cookie);
qmlCookie = new QmlCookie(netCookie);
m_cookies.insert(netCookie, qmlCookie);
}
return qmlCookie;
}

View File

@ -27,7 +27,7 @@ QmlCookies::QmlCookies(QObject *parent)
{
connect(mApp->cookieJar(), &CookieJar::cookieAdded, this, [this](QNetworkCookie network_cookie){
// FIXME: improve this
QmlCookie *cookie = cookieData->get(new QNetworkCookie(network_cookie));
QmlCookie *cookie = cookieData->get(&network_cookie);
QVariantMap map;
map.insert(QSL("cookie"), QVariant::fromValue(cookie));
map.insert(QSL("removed"), false);
@ -36,7 +36,7 @@ QmlCookies::QmlCookies(QObject *parent)
connect(mApp->cookieJar(), &CookieJar::cookieRemoved, this, [this](QNetworkCookie network_cookie){
// FIXME: improve this
QmlCookie *cookie = cookieData->get(new QNetworkCookie(network_cookie));
QmlCookie *cookie = cookieData->get(&network_cookie);
QVariantMap map;
map.insert(QSL("cookie"), QVariant::fromValue(cookie));
map.insert(QSL("removed"), true);
@ -53,10 +53,9 @@ QNetworkCookie *QmlCookies::getNetworkCookie(const QVariantMap &map)
const QString name = map.value(QSL("name")).toString();
const QString url = map.value(QSL("url")).toString();
QVector<QNetworkCookie> cookies = mApp->cookieJar()->getAllCookies();
for (const QNetworkCookie &cookie : cookies) {
for (const QNetworkCookie &cookie : qAsConst(cookies)) {
if (cookie.name() == name && cookie.domain() == url) {
QNetworkCookie *netCookie = new QNetworkCookie(cookie);
return netCookie;
return new QNetworkCookie(cookie);
}
}
return nullptr;
@ -105,14 +104,13 @@ QList<QObject*> QmlCookies::getAll(const QVariantMap &map)
const bool secure = map.value(QSL("secure")).toBool();
const bool session = map.value(QSL("session")).toBool();
QVector<QNetworkCookie> cookies = mApp->cookieJar()->getAllCookies();
for (QNetworkCookie cookie : cookies) {
for (QNetworkCookie cookie : qAsConst(cookies)) {
if ((!map.contains(QSL("name")) || cookie.name() == name)
&& (!map.contains(QSL("url")) || cookie.domain() == url)
&& (!map.contains(QSL("path")) || cookie.path() == path)
&& (!map.contains(QSL("secure")) || cookie.isSecure() == secure)
&& (!map.contains(QSL("session")) || cookie.isSessionCookie() == session)) {
QNetworkCookie *netCookie = new QNetworkCookie(cookie);
QmlCookie *qmlCookie = cookieData->get(netCookie);
QmlCookie *qmlCookie = cookieData->get(&cookie);
qmlCookies.append(qmlCookie);
}
}