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

KNewStuff

entryloader.cpp

Go to the documentation of this file.
00001 /*
00002     This file is part of KNewStuff2.
00003     Copyright (c) 2007 Josef Spillner <spillner@kde.org>
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018     Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "entryloader.h"
00022 
00023 #include "entryhandler.h"
00024 #include "feed.h"
00025 
00026 #include <QtCore/QByteArray>
00027 
00028 #include <kconfig.h>
00029 #include <kdebug.h>
00030 #include <kio/job.h>
00031 #include <klocale.h>
00032 
00033 using namespace KNS;
00034 
00035 EntryLoader::EntryLoader(QObject* parent)
00036         : QObject(parent)
00037 {
00038     m_feed = 0;
00039     m_provider = 0;
00040 }
00041 
00042 void EntryLoader::load(const Provider *provider, Feed *feed)
00043 {
00044     //kDebug() << "EntryLoader::load()";
00045 
00046     m_provider = provider;
00047     m_feed = feed;
00048 
00049     m_entries.clear();
00050     m_jobdata.clear();
00051 
00052     KUrl stuffurl = feed->feedUrl();
00053     //kDebug() << "EntryLoader::load(): stuffUrl: " << stuffurl.url();
00054 
00055     KIO::TransferJob *job = KIO::get(stuffurl, KIO::NoReload, KIO::HideProgressInfo);
00056     connect(job, SIGNAL(result(KJob *)),
00057             SLOT(slotJobResult(KJob *)));
00058     connect(job, SIGNAL(data(KIO::Job *, const QByteArray &)),
00059             SLOT(slotJobData(KIO::Job *, const QByteArray &)));
00060     connect(job, SIGNAL(percent(KJob*, unsigned long)),
00061             this, SIGNAL(signalProgress(KJob*, unsigned long)));
00062 }
00063 
00064 Feed *EntryLoader::feed() const
00065 {
00066     return m_feed;
00067 }
00068 
00069 const Provider *EntryLoader::provider() const
00070 {
00071     return m_provider;
00072 }
00073 
00074 void EntryLoader::slotJobData(KIO::Job *, const QByteArray &data)
00075 {
00076     //kDebug(550) << "EntryLoader::slotJobData()";
00077 
00078     m_jobdata.append(data);
00079 }
00080 
00081 void EntryLoader::slotJobResult(KJob *job)
00082 {
00083     if (job->error()) {
00084         emit signalEntriesFailed();
00085         return;
00086     }
00087 
00088     //QString contents = QString::fromUtf8(m_jobdata);
00089 
00090     //kDebug() << "--ENTRIES-START--";
00091     //kDebug() << QString::fromUtf8(m_jobdata);
00092     //kDebug() << "--ENTRIES-END--";
00093 
00094     QDomDocument doc;
00095     if (!doc.setContent(m_jobdata)) {
00096         emit signalEntriesFailed();
00097         return;
00098     }
00099 
00100     QDomElement entries = doc.documentElement();
00101 
00102     if (entries.isNull()) {
00103         kWarning() << "No document in stuff.xml.";
00104     }
00105 
00106     QDomNode n;
00107     for (n = entries.firstChild(); !n.isNull(); n = n.nextSibling()) {
00108         QDomElement e = n.toElement();
00109 
00110         if (e.tagName() == "stuff") {
00111             EntryHandler handler(e);
00112             Entry * entry = handler.entryptr();
00113             m_entries.append(entry);
00114             m_feed->addEntry(entry);
00115             //kDebug() << " entry " << entry->name().representation() << " loaded from provider";
00116         }
00117     }
00118 
00119     emit signalEntriesLoaded(m_entries);
00120 }
00121 
00122 #include "entryloader.moc"

KNewStuff

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal