|
1 /* |
|
2 Copyright (C) 2007 Staikos Computing Services Inc. |
|
3 |
|
4 This library is free software; you can redistribute it and/or |
|
5 modify it under the terms of the GNU Library General Public |
|
6 License as published by the Free Software Foundation; either |
|
7 version 2 of the License, or (at your option) any later version. |
|
8 |
|
9 This library is distributed in the hope that it will be useful, |
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
12 Library General Public License for more details. |
|
13 |
|
14 You should have received a copy of the GNU Library General Public License |
|
15 along with this library; see the file COPYING.LIB. If not, write to |
|
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
17 Boston, MA 02110-1301, USA. |
|
18 */ |
|
19 |
|
20 |
|
21 #include "qcookiejar.h" |
|
22 #include <QCoreApplication> |
|
23 uint qHash(const QUrl&); |
|
24 #include <QHash> |
|
25 #include <QPointer> |
|
26 |
|
27 class QCookieJarPrivate { |
|
28 public: |
|
29 QCookieJarPrivate() { |
|
30 enabled = true; |
|
31 } |
|
32 bool enabled; |
|
33 QHash<QUrl, QString> jar; |
|
34 }; |
|
35 |
|
36 |
|
37 uint qHash(const QUrl& url) { |
|
38 return qHash(url.toString()); |
|
39 } |
|
40 |
|
41 |
|
42 QCookieJar::QCookieJar() |
|
43 : QObject(), d(new QCookieJarPrivate) |
|
44 { |
|
45 } |
|
46 |
|
47 |
|
48 QCookieJar::~QCookieJar() |
|
49 { |
|
50 delete d; |
|
51 } |
|
52 |
|
53 |
|
54 void QCookieJar::setCookies(const QUrl& url, const QUrl& policyUrl, const QString& value) |
|
55 { |
|
56 Q_UNUSED(policyUrl) |
|
57 d->jar.insert(url, value); |
|
58 } |
|
59 |
|
60 |
|
61 QString QCookieJar::cookies(const QUrl& url) |
|
62 { |
|
63 return d->jar.value(url); |
|
64 } |
|
65 |
|
66 |
|
67 bool QCookieJar::isEnabled() const |
|
68 { |
|
69 return d->enabled; |
|
70 } |
|
71 |
|
72 |
|
73 void QCookieJar::setEnabled(bool enabled) |
|
74 { |
|
75 d->enabled = enabled; |
|
76 } |
|
77 |
|
78 |
|
79 static QPointer<QCookieJar> gJar; |
|
80 static bool gRoutineAdded = false; |
|
81 |
|
82 static void gCleanupJar() |
|
83 { |
|
84 delete gJar; |
|
85 } |
|
86 |
|
87 |
|
88 void QCookieJar::setCookieJar(QCookieJar *jar) |
|
89 { |
|
90 if (!gRoutineAdded) { |
|
91 qAddPostRoutine(gCleanupJar); |
|
92 gRoutineAdded = true; |
|
93 } |
|
94 delete gJar; |
|
95 gJar = jar; |
|
96 } |
|
97 |
|
98 |
|
99 QCookieJar *QCookieJar::cookieJar() |
|
100 { |
|
101 if (!gJar) { |
|
102 setCookieJar(new QCookieJar); |
|
103 } |
|
104 return gJar; |
|
105 } |