• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kde-baseapps API Reference
  • KDE Home
  • Contact Us
 

libkonq

  • sources
  • kde-4.14
  • kde-baseapps
  • lib
  • konq
konq_historyloader.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE project
2  Copyright 2009 David Faure <faure@kde.org>
3 
4  This library is free software; you can redistribute it and/or modify
5  it under the terms of the GNU Library General Public License as published
6  by the Free Software Foundation; either version 2 of the License or
7  ( at your option ) version 3 or, at the discretion of KDE e.V.
8  ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #include "konq_historyloader.h"
22 #include <kdebug.h>
23 #include <QFile>
24 #include <kstandarddirs.h>
25 #include "konq_historyentry.h"
26 #include <zlib.h> // for crc32
27 
28 class KonqHistoryLoaderPrivate
29 {
30 public:
31  KonqHistoryList m_history;
32 };
33 
34 KonqHistoryLoader::KonqHistoryLoader(QObject* parent)
35  : QObject(parent), d(new KonqHistoryLoaderPrivate)
36 {
37  loadHistory();
38 }
39 
40 KonqHistoryLoader::~KonqHistoryLoader()
41 {
42  delete d;
43 }
44 
49 static bool lastVisitedOrder( const KonqHistoryEntry& lhs, const KonqHistoryEntry& rhs ) {
50  return lhs.lastVisited < rhs.lastVisited;
51 }
52 
53 bool KonqHistoryLoader::loadHistory()
54 {
55  d->m_history.clear();
56 
57  const QString filename = KStandardDirs::locateLocal("data", QLatin1String("konqueror/konq_history"));
58  QFile file(filename);
59  if (!file.open(QIODevice::ReadOnly)) {
60  if (file.exists())
61  kWarning() << "Can't open" << filename;
62  return false;
63  }
64 
65  QDataStream fileStream(&file);
66  QByteArray data; // only used for version == 2
67  // we construct the stream object now but fill in the data later.
68  QDataStream crcStream(&data, QIODevice::ReadOnly);
69  KonqHistoryEntry::Flags flags = KonqHistoryEntry::NoFlags;
70 
71  if (!fileStream.atEnd()) {
72  quint32 version;
73  fileStream >> version;
74 
75  QDataStream *stream = &fileStream;
76 
77  bool crcChecked = false;
78  bool crcOk = false;
79 
80  if (version >= 2 && version <= 4) {
81  quint32 crc;
82  crcChecked = true;
83  fileStream >> crc >> data;
84  crcOk = crc32(0, reinterpret_cast<unsigned char *>(data.data()), data.size()) == crc;
85  stream = &crcStream; // pick up the right stream
86  }
87 
88  // We can't read v3 history anymore, because operator<<(KURL) disappeared.
89 
90  if (version == 4)
91  {
92  // Use QUrl marshalling for V4 format.
93  flags = KonqHistoryEntry::NoFlags;
94  }
95 
96 #if 0 // who cares for versions 1 and 2 nowadays...
97  if (version != 0 && version < 3) //Versions 1,2 (but not 0) are also valid
98  {
99  //Turn on backwards compatibility mode..
100  marshalURLAsStrings = true;
101  // it doesn't make sense to save to save maxAge and maxCount in the
102  // binary file, this would make backups impossible (they would clear
103  // themselves on startup, because all entries expire).
104  // [But V1 and V2 formats did it, so we do a dummy read]
105  quint32 dummy;
106  *stream >> dummy;
107  *stream >> dummy;
108 
109  //OK.
110  version = 3;
111  }
112 #endif
113 
114  if (historyVersion() != (int)version || (crcChecked && !crcOk)) {
115  kWarning() << "The history version doesn't match, aborting loading" ;
116  file.close();
117  return false;
118  }
119 
120  while (!stream->atEnd()) {
121  KonqHistoryEntry entry;
122  entry.load(*stream, flags);
123  // kDebug(1202) << "loaded entry:" << entry.url << ", Title:" << entry.title;
124  d->m_history.append(entry);
125  }
126 
127  //kDebug(1202) << "loaded:" << m_history.count() << "entries.";
128 
129  qSort(d->m_history.begin(), d->m_history.end(), lastVisitedOrder);
130  }
131 
132  // Theoretically, we should emit update() here, but as we only ever
133  // load items on startup up to now, this doesn't make much sense.
134  // emit KParts::HistoryProvider::update(some list);
135  return true;
136 }
137 
138 const KonqHistoryList& KonqHistoryLoader::entries() const
139 {
140  return d->m_history;
141 }
142 
143 int KonqHistoryLoader::historyVersion()
144 {
145  return 4;
146 }
KonqHistoryLoader::historyVersion
static int historyVersion()
Definition: konq_historyloader.cpp:143
QByteArray
QDataStream
KonqHistoryLoader::entries
const KonqHistoryList & entries() const
Definition: konq_historyloader.cpp:138
KonqHistoryLoader::~KonqHistoryLoader
virtual ~KonqHistoryLoader()
Definition: konq_historyloader.cpp:40
QFile::exists
bool exists() const
KonqHistoryLoader::KonqHistoryLoader
KonqHistoryLoader(QObject *parent=0)
Definition: konq_historyloader.cpp:34
QFile
konq_historyloader.h
QObject
QString
KonqHistoryEntry::load
void load(QDataStream &s, Flags flags)
Definition: konq_historyentry.cpp:43
QFile::open
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
QDataStream::atEnd
bool atEnd() const
KonqHistoryLoader::loadHistory
bool loadHistory()
Load the history.
Definition: konq_historyloader.cpp:53
KonqHistoryEntry::NoFlags
Definition: konq_historyentry.h:47
QFile::close
virtual void close()
konq_historyentry.h
KonqHistoryList
Definition: konq_historyentry.h:62
QLatin1String
KonqHistoryEntry::Flags
Flags
Definition: konq_historyentry.h:47
lastVisitedOrder
static bool lastVisitedOrder(const KonqHistoryEntry &lhs, const KonqHistoryEntry &rhs)
Ensures that the items are sorted by the lastVisited date (oldest goes first)
Definition: konq_historyloader.cpp:49
KonqHistoryEntry::lastVisited
QDateTime lastVisited
Definition: konq_historyentry.h:40
KonqHistoryEntry
Definition: konq_historyentry.h:29
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:07:48 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkonq

Skip menu "libkonq"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kde-baseapps API Reference

Skip menu "kde-baseapps API Reference"
  • Libraries
  •   libkonq

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal