#include "config.h"
#include "qcookiejar.h"
#include <QCoreApplication>
uint qHash(const QUrl&);
#include <QHash>
#include <QPointer>
class QCookieJarPrivate {
public:
QCookieJarPrivate() {
enabled = true;
}
bool enabled;
QHash<QUrl, QString> jar;
};
uint qHash(const QUrl& url) {
return qHash(url.toString());
}
QCookieJar::QCookieJar()
: QObject(), d(new QCookieJarPrivate)
{
}
QCookieJar::~QCookieJar()
{
delete d;
}
void QCookieJar::setCookies(const QUrl& url, const QUrl& policyUrl, const QString& value)
{
Q_UNUSED(policyUrl)
d->jar.insert(url, value);
}
QString QCookieJar::cookies(const QUrl& url)
{
return d->jar.value(url);
}
bool QCookieJar::isEnabled() const
{
return d->enabled;
}
void QCookieJar::setEnabled(bool enabled)
{
d->enabled = enabled;
}
static QPointer<QCookieJar> gJar;
static bool gRoutineAdded = false;
static void gCleanupJar()
{
delete gJar;
}
void QCookieJar::setCookieJar(QCookieJar *jar)
{
if (!gRoutineAdded) {
qAddPostRoutine(gCleanupJar);
gRoutineAdded = true;
}
delete gJar;
gJar = jar;
}
QCookieJar *QCookieJar::cookieJar()
{
if (!gJar) {
setCookieJar(new QCookieJar);
}
return gJar;
}