• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KNewStuff

  • knewstuff
  • knewstuff2
  • core
entryloader.cpp
Go to the documentation of this file.
1/*
2 This file is part of KNewStuff2.
3 Copyright (c) 2007 Josef Spillner <spillner@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19#include "entryloader.h"
20
21#include "entryhandler.h"
22#include "feed.h"
23
24#include <QtCore/QByteArray>
25
26#include <kconfig.h>
27#include <kdebug.h>
28#include <kio/job.h>
29#include <klocale.h>
30
31using namespace KNS;
32
33EntryLoader::EntryLoader(QObject* parent)
34 : QObject(parent)
35{
36 m_feed = 0;
37 m_provider = 0;
38}
39
40void EntryLoader::load(const Provider *provider, Feed *feed)
41{
42 //kDebug() << "EntryLoader::load()";
43
44 m_provider = provider;
45 m_feed = feed;
46
47 m_entries.clear();
48 m_jobdata.clear();
49
50 KUrl stuffurl = feed->feedUrl();
51 //kDebug() << "EntryLoader::load(): stuffUrl: " << stuffurl.url();
52
53 KIO::TransferJob *job = KIO::get(stuffurl, KIO::NoReload, KIO::HideProgressInfo);
54 connect(job, SIGNAL(result(KJob*)),
55 SLOT(slotJobResult(KJob*)));
56 connect(job, SIGNAL(data(KIO::Job*,QByteArray)),
57 SLOT(slotJobData(KIO::Job*,QByteArray)));
58 connect(job, SIGNAL(percent(KJob*,ulong)),
59 this, SIGNAL(signalProgress(KJob*,ulong)));
60}
61
62Feed *EntryLoader::feed() const
63{
64 return m_feed;
65}
66
67const Provider *EntryLoader::provider() const
68{
69 return m_provider;
70}
71
72void EntryLoader::slotJobData(KIO::Job *, const QByteArray &data)
73{
74 //kDebug(550) << "EntryLoader::slotJobData()";
75
76 m_jobdata.append(data);
77}
78
79void EntryLoader::slotJobResult(KJob *job)
80{
81 if (job->error()) {
82 emit signalEntriesFailed();
83 return;
84 }
85
86 //QString contents = QString::fromUtf8(m_jobdata);
87
88 //kDebug() << "--ENTRIES-START--";
89 //kDebug() << QString::fromUtf8(m_jobdata);
90 //kDebug() << "--ENTRIES-END--";
91
92 QDomDocument doc;
93 if (!doc.setContent(m_jobdata)) {
94 emit signalEntriesFailed();
95 return;
96 }
97
98 QDomElement entries = doc.documentElement();
99
100 if (entries.isNull()) {
101 kWarning() << "No document in stuff.xml.";
102 }
103
104 QDomNode n;
105 for (n = entries.firstChild(); !n.isNull(); n = n.nextSibling()) {
106 QDomElement e = n.toElement();
107
108 if (e.tagName() == "stuff") {
109 EntryHandler handler(e);
110 Entry * entry = handler.entryptr();
111 m_entries.append(entry);
112 m_feed->addEntry(entry);
113 //kDebug() << " entry " << entry->name().representation() << " loaded from provider";
114 }
115 }
116
117 emit signalEntriesLoaded(m_entries);
118}
119
120#include "entryloader.moc"
KIO::Job
KIO::TransferJob
KJob
KJob::error
int error() const
KNS::EntryHandler
Parser and dumper for KNewStuff data entries.
Definition: entryhandler.h:43
KNS::EntryHandler::entryptr
Entry * entryptr()
Definition: entryhandler.cpp:67
KNS::EntryLoader::feed
Feed * feed() const
Returns the feed which was used for download.
Definition: entryloader.cpp:62
KNS::EntryLoader::slotJobResult
void slotJobResult(KJob *)
Definition: entryloader.cpp:79
KNS::EntryLoader::provider
const Provider * provider() const
Returns the provider which was used for download.
Definition: entryloader.cpp:67
KNS::EntryLoader::signalProgress
void signalProgress(KJob *, unsigned long)
report progress loading
KNS::EntryLoader::signalEntriesFailed
void signalEntriesFailed()
Indicates that the list of entries could not be loaded.
KNS::EntryLoader::load
void load(const Provider *provider, Feed *feed)
Starts asynchronously loading the list of entries from the given provider for the given feed.
Definition: entryloader.cpp:40
KNS::EntryLoader::EntryLoader
EntryLoader(QObject *parent)
Constructor.
Definition: entryloader.cpp:33
KNS::EntryLoader::slotJobData
void slotJobData(KIO::Job *, const QByteArray &)
Definition: entryloader.cpp:72
KNS::EntryLoader::signalEntriesLoaded
void signalEntriesLoaded(KNS::Entry::List list)
Indicates that the list of entries has been successfully loaded.
KNS::Entry
KNewStuff data entry container.
Definition: knewstuff2/core/entry.h:47
KNS::Feed
KNewStuff feed.
Definition: feed.h:46
KNS::Feed::feedUrl
KUrl feedUrl() const
Retrieve the URL of the feed.
Definition: feed.cpp:67
KNS::Feed::addEntry
void addEntry(Entry *entry)
Adds an association to an entry.
Definition: feed.cpp:72
KNS::Provider
KNewStuff provider container.
Definition: knewstuff2/core/provider.h:52
KUrl
QObject
entryhandler.h
entryloader.h
feed.h
kWarning
#define kWarning
job.h
kconfig.h
kdebug.h
klocale.h
KIO::get
TransferJob * get(const KUrl &url, LoadType reload=NoReload, JobFlags flags=DefaultFlags)
KIO::NoReload
NoReload
KIO::HideProgressInfo
HideProgressInfo
KNS
Definition: knewstuff2/core/author.h:27
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KNewStuff

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

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
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