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

KNewStuff

  • sources
  • kde-4.12
  • kdelibs
  • 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 
31 using namespace KNS;
32 
33 EntryLoader::EntryLoader(QObject* parent)
34  : QObject(parent)
35 {
36  m_feed = 0;
37  m_provider = 0;
38 }
39 
40 void 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 
62 Feed *EntryLoader::feed() const
63 {
64  return m_feed;
65 }
66 
67 const Provider *EntryLoader::provider() const
68 {
69  return m_provider;
70 }
71 
72 void EntryLoader::slotJobData(KIO::Job *, const QByteArray &data)
73 {
74  //kDebug(550) << "EntryLoader::slotJobData()";
75 
76  m_jobdata.append(data);
77 }
78 
79 void 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"
KNS::EntryHandler::entryptr
Entry * entryptr()
Definition: entryhandler.cpp:67
kdebug.h
KNS::Entry
KNewStuff data entry container.
Definition: knewstuff2/core/entry.h:46
KIO::HideProgressInfo
kconfig.h
KNS::EntryLoader::provider
const Provider * provider() const
Returns the provider which was used for download.
Definition: entryloader.cpp:67
KIO::get
TransferJob * get(const KUrl &url, LoadType reload=NoReload, JobFlags flags=DefaultFlags)
KNS::EntryLoader::signalEntriesLoaded
void signalEntriesLoaded(KNS::Entry::List list)
Indicates that the list of entries has been successfully loaded.
QObject
klocale.h
feed.h
KUrl
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
entryloader.h
KNS::EntryLoader::signalProgress
void signalProgress(KJob *, unsigned long)
report progress loading
KNS::Feed::feedUrl
KUrl feedUrl() const
Retrieve the URL of the feed.
Definition: feed.cpp:67
KNS::EntryLoader::feed
Feed * feed() const
Returns the feed which was used for download.
Definition: entryloader.cpp:62
entryhandler.h
KNS::Feed::addEntry
void addEntry(Entry *entry)
Adds an association to an entry.
Definition: feed.cpp:72
KNS::EntryLoader::signalEntriesFailed
void signalEntriesFailed()
Indicates that the list of entries could not be loaded.
job.h
KIO::Job
KIO::NoReload
kWarning
static QDebug kWarning(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
KNS::EntryLoader::slotJobResult
void slotJobResult(KJob *)
Definition: entryloader.cpp:79
KIO::TransferJob
KNS::EntryLoader::slotJobData
void slotJobData(KIO::Job *, const QByteArray &)
Definition: entryloader.cpp:72
KNS::Feed
KNewStuff feed.
Definition: feed.h:45
KNS::EntryHandler
Parser and dumper for KNewStuff data entries.
Definition: entryhandler.h:42
KJob
KNS::Provider
KNewStuff provider container.
Definition: knewstuff2/core/provider.h:51
KNS::EntryLoader::EntryLoader
EntryLoader(QObject *parent)
Constructor.
Definition: entryloader.cpp:33
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:50:48 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

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