|
1 /* |
|
2 Copyright (C) 2007 Trolltech ASA |
|
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 This class provides all functionality needed for loading images, style sheets and html |
|
20 pages from the web. It has a memory cache for these objects. |
|
21 */ |
|
22 #include "qwebpagehistory.h" |
|
23 #include "qwebpagehistory_p.h" |
|
24 |
|
25 #include "DeprecatedString.h" |
|
26 #include "PlatformString.h" |
|
27 #include "Image.h" |
|
28 |
|
29 #include <QSharedData> |
|
30 |
|
31 QWebHistoryItem::QWebHistoryItem(const QWebHistoryItem &other) |
|
32 : d(other.d) |
|
33 { |
|
34 } |
|
35 |
|
36 QWebHistoryItem &QWebHistoryItem::operator=(const QWebHistoryItem &other) |
|
37 { |
|
38 d = other.d; |
|
39 return *this; |
|
40 } |
|
41 |
|
42 QWebHistoryItem::~QWebHistoryItem() |
|
43 { |
|
44 } |
|
45 |
|
46 QUrl QWebHistoryItem::originalUrl() const |
|
47 { |
|
48 return QUrl(d->item->originalURL().url()); |
|
49 } |
|
50 |
|
51 |
|
52 QUrl QWebHistoryItem::currentUrl() const |
|
53 { |
|
54 return QUrl(d->item->url().url()); |
|
55 } |
|
56 |
|
57 |
|
58 QString QWebHistoryItem::title() const |
|
59 { |
|
60 return d->item->title(); |
|
61 } |
|
62 |
|
63 |
|
64 QDateTime QWebHistoryItem::lastVisited() const |
|
65 { |
|
66 //FIXME : this will be wrong unless we correctly set lastVisitedTime ourselves |
|
67 return QDateTime::fromTime_t((uint)d->item->lastVisitedTime()); |
|
68 } |
|
69 |
|
70 |
|
71 QPixmap QWebHistoryItem::icon() const |
|
72 { |
|
73 return *d->item->icon()->getPixmap(); |
|
74 } |
|
75 |
|
76 |
|
77 QWebHistoryItem::QWebHistoryItem(QWebHistoryItemPrivate *priv) |
|
78 { |
|
79 d = priv; |
|
80 } |
|
81 |
|
82 QWebPageHistory::QWebPageHistory(QWebPageHistoryPrivate *priv) |
|
83 { |
|
84 d = priv; |
|
85 } |
|
86 |
|
87 QWebPageHistory::QWebPageHistory(const QWebPageHistory &other) |
|
88 { |
|
89 d = other.d; |
|
90 } |
|
91 |
|
92 QWebPageHistory &QWebPageHistory::operator=(const QWebPageHistory &other) |
|
93 { |
|
94 d = other.d; |
|
95 return *this; |
|
96 } |
|
97 |
|
98 QWebPageHistory::~QWebPageHistory() |
|
99 { |
|
100 } |
|
101 |
|
102 void QWebPageHistory::clear() |
|
103 { |
|
104 RefPtr<WebCore::HistoryItem> current = d->lst->currentItem(); |
|
105 int capacity = d->lst->capacity(); |
|
106 d->lst->setCapacity(0); |
|
107 d->lst->setCapacity(capacity); |
|
108 d->lst->addItem(current.get()); |
|
109 d->lst->goToItem(current.get()); |
|
110 } |
|
111 |
|
112 QList<QWebHistoryItem> QWebPageHistory::items() const |
|
113 { |
|
114 const WebCore::HistoryItemVector &items = d->lst->entries(); |
|
115 |
|
116 QList<QWebHistoryItem> ret; |
|
117 for (int i = 0; i < items.size(); ++i) { |
|
118 QWebHistoryItemPrivate *priv = new QWebHistoryItemPrivate(items[i].get()); |
|
119 ret.append(QWebHistoryItem(priv)); |
|
120 } |
|
121 return ret; |
|
122 } |
|
123 |
|
124 QList<QWebHistoryItem> QWebPageHistory::backItems(int maxItems) const |
|
125 { |
|
126 WebCore::HistoryItemVector items(maxItems); |
|
127 d->lst->backListWithLimit(maxItems, items); |
|
128 |
|
129 QList<QWebHistoryItem> ret; |
|
130 for (int i = 0; i < items.size(); ++i) { |
|
131 QWebHistoryItemPrivate *priv = new QWebHistoryItemPrivate(items[i].get()); |
|
132 ret.append(QWebHistoryItem(priv)); |
|
133 } |
|
134 return ret; |
|
135 } |
|
136 |
|
137 QList<QWebHistoryItem> QWebPageHistory::forwardItems(int maxItems) const |
|
138 { |
|
139 WebCore::HistoryItemVector items(maxItems); |
|
140 d->lst->forwardListWithLimit(maxItems, items); |
|
141 |
|
142 QList<QWebHistoryItem> ret; |
|
143 for (int i = 0; i < items.size(); ++i) { |
|
144 QWebHistoryItemPrivate *priv = new QWebHistoryItemPrivate(items[i].get()); |
|
145 ret.append(QWebHistoryItem(priv)); |
|
146 } |
|
147 return ret; |
|
148 } |
|
149 |
|
150 bool QWebPageHistory::canGoBack() const |
|
151 { |
|
152 return d->lst->backListCount() > 0; |
|
153 } |
|
154 |
|
155 bool QWebPageHistory::canGoForward() const |
|
156 { |
|
157 return d->lst->forwardListCount() > 0; |
|
158 } |
|
159 |
|
160 void QWebPageHistory::goBack() |
|
161 { |
|
162 d->lst->goBack(); |
|
163 } |
|
164 |
|
165 void QWebPageHistory::goForward() |
|
166 { |
|
167 d->lst->goBack(); |
|
168 } |
|
169 |
|
170 void QWebPageHistory::goToItem(QWebHistoryItem *item) |
|
171 { |
|
172 d->lst->goToItem(item->d->item); |
|
173 } |
|
174 |
|
175 QWebHistoryItem QWebPageHistory::backItem() const |
|
176 { |
|
177 WebCore::HistoryItem *i = d->lst->backItem(); |
|
178 QWebHistoryItemPrivate *priv = new QWebHistoryItemPrivate(i); |
|
179 return QWebHistoryItem(priv); |
|
180 } |
|
181 |
|
182 QWebHistoryItem QWebPageHistory::currentItem() const |
|
183 { |
|
184 WebCore::HistoryItem *i = d->lst->currentItem(); |
|
185 QWebHistoryItemPrivate *priv = new QWebHistoryItemPrivate(i); |
|
186 return QWebHistoryItem(priv); |
|
187 } |
|
188 |
|
189 QWebHistoryItem QWebPageHistory::forwardItem() const |
|
190 { |
|
191 WebCore::HistoryItem *i = d->lst->forwardItem(); |
|
192 QWebHistoryItemPrivate *priv = new QWebHistoryItemPrivate(i); |
|
193 return QWebHistoryItem(priv); |
|
194 } |
|
195 |
|
196 QWebHistoryItem QWebPageHistory::itemAtIndex(int i) const |
|
197 { |
|
198 WebCore::HistoryItem *item = d->lst->itemAtIndex(i); |
|
199 |
|
200 QWebHistoryItemPrivate *priv = new QWebHistoryItemPrivate(item); |
|
201 return QWebHistoryItem(priv); |
|
202 } |
|
203 |