History support on platform Qt. r=lars
[WebKit-https.git] / WebKitQt / Api / qwebpagehistory.cpp
1 #include "qwebpagehistory.h"
2 #include "qwebpagehistory_p.h"
3
4 #include "DeprecatedString.h"
5 #include "PlatformString.h"
6 #include "Image.h"
7
8 #include <QSharedData>
9
10 QWebHistoryItem::~QWebHistoryItem()
11 {
12 }
13
14 QUrl QWebHistoryItem::originalUrl() const
15 {
16     return QUrl(d->item->originalURL().url());
17 }
18
19
20 QUrl QWebHistoryItem::currentUrl() const
21 {
22     return QUrl(d->item->url().url());
23 }
24
25
26 QString QWebHistoryItem::title() const
27 {
28     return d->item->title();
29 }
30
31
32 QDateTime QWebHistoryItem::lastVisited() const
33 {
34     //FIXME : this will be wrong unless we correctly set lastVisitedTime ourselves
35     return QDateTime::fromTime_t((uint)d->item->lastVisitedTime());
36 }
37
38
39 QPixmap QWebHistoryItem::icon() const
40 {
41     return *d->item->icon()->getPixmap();
42 }
43
44
45 QWebHistoryItem::QWebHistoryItem(QWebHistoryItemPrivate *priv)
46 {
47     d = priv;
48 }
49
50 QWebPageHistory::QWebPageHistory(QWebPageHistoryPrivate *priv)
51 {
52     d = priv;
53 }
54
55 QWebHistoryItem QWebPageHistory::itemAtIndex(int i) const
56 {
57     WebCore::HistoryItem *item = d->lst->itemAtIndex(i);
58
59     QWebHistoryItemPrivate *priv = new QWebHistoryItemPrivate(item);
60     return QWebHistoryItem(priv);
61 }
62
63 QWebPageHistory::QWebPageHistory(const QWebPageHistory &other)
64 {
65     d = other.d;
66 }
67
68 QWebPageHistory::~QWebPageHistory()
69 {
70 }
71
72 QList<QWebHistoryItem> QWebPageHistory::items() const
73 {
74     const WebCore::HistoryItemVector &items = d->lst->entries();
75
76     QList<QWebHistoryItem> ret;
77     for (int i = 0; i < items.size(); ++i) {
78         QWebHistoryItemPrivate *priv = new QWebHistoryItemPrivate(items[i].get());
79         ret.append(QWebHistoryItem(priv));
80     }
81     return ret;
82 }
83
84 QList<QWebHistoryItem> QWebPageHistory::backItems(int maxItems) const
85 {
86     WebCore::HistoryItemVector items(maxItems);
87     d->lst->backListWithLimit(maxItems, items);
88
89     QList<QWebHistoryItem> ret;
90     for (int i = 0; i < items.size(); ++i) {
91         QWebHistoryItemPrivate *priv = new QWebHistoryItemPrivate(items[i].get());
92         ret.append(QWebHistoryItem(priv));
93     }
94     return ret;
95 }
96
97 QList<QWebHistoryItem> QWebPageHistory::forwardItems(int maxItems) const
98 {
99     WebCore::HistoryItemVector items(maxItems);
100     d->lst->forwardListWithLimit(maxItems, items);
101
102     QList<QWebHistoryItem> ret;
103     for (int i = 0; i < items.size(); ++i) {
104         QWebHistoryItemPrivate *priv = new QWebHistoryItemPrivate(items[i].get());
105         ret.append(QWebHistoryItem(priv));
106     }
107     return ret;
108 }
109
110 void QWebPageHistory::goBack()
111 {
112     d->lst->goBack();
113 }
114
115 void QWebPageHistory::goForward()
116 {
117     d->lst->goBack();
118 }
119
120 void QWebPageHistory::goToItem(QWebHistoryItem *item)
121 {
122     d->lst->goToItem(item->d->item);
123 }
124
125 QWebHistoryItem QWebPageHistory::backItem() const
126 {
127     WebCore::HistoryItem *i = d->lst->backItem();
128     QWebHistoryItemPrivate *priv = new QWebHistoryItemPrivate(i);
129     return QWebHistoryItem(priv);
130 }
131
132 QWebHistoryItem QWebPageHistory::currentItem() const
133 {
134     WebCore::HistoryItem *i = d->lst->currentItem();
135     QWebHistoryItemPrivate *priv = new QWebHistoryItemPrivate(i);
136     return QWebHistoryItem(priv);
137 }
138
139 QWebHistoryItem QWebPageHistory::forwardItem() const
140 {
141     WebCore::HistoryItem *i = d->lst->forwardItem();
142     QWebHistoryItemPrivate *priv = new QWebHistoryItemPrivate(i);
143     return QWebHistoryItem(priv);
144 }
145