1/*
2    Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
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#include "config.h"
21#include "HistoryItem.h"
22
23#include "FormData.h"
24#include <wtf/text/CString.h>
25
26bool WebCore::HistoryItem::restoreState(QDataStream& in, int version)
27{
28    // we only support version 1 for now
29
30    if (version != 1)
31        return false;
32
33    WTF::String url;
34    WTF::String title;
35    WTF::String altTitle;
36    WTF::String orginalUrl;
37    WTF::String referrer;
38    WTF::String target;
39    WTF::String parrent;
40    double lastVisitedTime;
41    bool validUserData;
42    WTF::String parent;
43    bool lastVisitWasHTTPNonGet;
44    bool lastVisitWasFailure;
45    bool isTargetItem;
46    int visitCount;
47    WTF::Vector<WTF::String> documentState;
48    WebCore::IntPoint scrollPoint;
49    WTF::Vector<int> weeklyVisitCounts;
50    WTF::Vector<int> dailyVisitCounts;
51    // bool loadFormdata;
52    // WTF::String formContentType;
53    // WTF::Vector<char> formData;
54
55    in >> url >> title >> altTitle >> lastVisitedTime >> orginalUrl >> referrer >> target >> parent;
56    in >> lastVisitWasHTTPNonGet >> lastVisitWasFailure >> isTargetItem >> visitCount >> documentState;
57    in >> scrollPoint >> dailyVisitCounts >> weeklyVisitCounts;
58    /*in >> loadFormdata;
59    if (loadFormdata) {
60        in >> formContentType >> formData;
61        // direct assigned (!)
62        m_formContentType = formContentType;
63        m_formData = FormData::create(CString(formData));
64    }*/
65    // use setters
66    adoptVisitCounts(dailyVisitCounts, weeklyVisitCounts);
67    setScrollPoint(scrollPoint);
68    setDocumentState(documentState);
69    setVisitCount(visitCount);
70    setIsTargetItem(isTargetItem);
71    setLastVisitWasFailure(lastVisitWasFailure);
72    setLastVisitWasHTTPNonGet(lastVisitWasHTTPNonGet);
73    setParent(parent);
74    setTarget(target);
75    setReferrer(referrer);
76    setOriginalURLString(orginalUrl);
77    setURLString(url);
78    setLastVisitedTime(lastVisitedTime);
79    setTitle(title);
80    setAlternateTitle(altTitle);
81
82    // at the end load userData
83    in >> validUserData;
84    if (validUserData) {
85        QVariant tmp;
86        in >> tmp;
87        setUserData(tmp);
88    }
89
90    return in.status() == QDataStream::Ok;
91}
92
93QDataStream& WebCore::HistoryItem::saveState(QDataStream& out, int version) const
94{
95    // we only support version 1 for now.
96    if (version != 1)
97        return out;
98
99    out << urlString() << title() << alternateTitle() << lastVisitedTime();
100    out << originalURLString() << referrer() << target() << parent();
101    out << lastVisitWasHTTPNonGet() << lastVisitWasFailure() << isTargetItem();
102    out << visitCount() << documentState() << scrollPoint();
103    out << dailyVisitCounts() << weeklyVisitCounts();
104    /*if (m_formData) {
105        out << true;
106        out << formContentType();
107        out << m_formData->flatten();
108    } else {
109        out << false;
110    }*/
111    // save user data
112    if (userData().isValid())
113        out << true << userData();
114    else
115        out << false;
116
117    return out;
118}
119
120