Syndication

documentsource.cpp
1 /*
2  This file is part of the syndication library
3  SPDX-FileCopyrightText: 2005 Frank Osterfeld <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #include "documentsource.h"
9 #include "tools.h"
10 
11 #include <QByteArray>
12 #include <QDebug>
13 #include <QDomDocument>
14 
15 namespace Syndication
16 {
17 class DocumentSource::DocumentSourcePrivate
18 {
19 public:
20  QByteArray array;
21  QString url;
22  mutable QDomDocument domDoc;
23  mutable bool parsed;
24  mutable unsigned int hash;
25  mutable bool calculatedHash;
26 };
27 
29  : d(new DocumentSourcePrivate)
30 {
31  d->parsed = true;
32  d->calculatedHash = true;
33  d->hash = 0;
34 }
35 
37  : d(new DocumentSourcePrivate)
38 {
39  d->array = source;
40  d->url = url;
41  d->calculatedHash = false;
42  d->parsed = false;
43 }
44 
46  : d()
47 {
48  *this = other;
49 }
50 
52 {
53 }
54 
56 {
57  d = other.d;
58  return *this;
59 }
60 
62 {
63  return d->array;
64 }
65 
67 {
68  if (!d->parsed) {
69  QString errorMsg;
70  int errorLine;
71  int errorColumn;
72  if (!d->domDoc.setContent(d->array, true, &errorMsg, &errorLine, &errorColumn)) {
73  qWarning() << errorMsg << "on line" << errorLine;
74  d->domDoc.clear();
75  }
76 
77  d->parsed = true;
78  }
79 
80  return d->domDoc;
81 }
82 
83 unsigned int DocumentSource::size() const
84 {
85  return d->array.size();
86 }
87 
88 unsigned int DocumentSource::hash() const
89 {
90  if (!d->calculatedHash) {
91  d->hash = calcHash(d->array);
92  d->calculatedHash = true;
93  }
94 
95  return d->hash;
96 }
97 
99 {
100  return d->url;
101 }
102 
103 } // namespace Syndication
unsigned int hash() const
calculates a hash value for the source array.
QDomDocument asDomDocument() const
Returns the feed source as DOM document.
Represents the source of a syndication document, as read from the downloaded file.
DocumentSource()
Creates an empty document source.
QString url() const
returns the URL the document source was loaded from
unsigned int size() const
returns the size the source array in bytes.
DocumentSource & operator=(const DocumentSource &other)
Assignment operator.
QByteArray asByteArray() const
Returns the feed source as byte array.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Tue Sep 27 2022 04:11:12 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.