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 Lesser General Public 00007 License as published by the Free Software Foundation; either 00008 version 2.1 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 Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public 00016 License along with this library. If not, see <http://www.gnu.org/licenses/>. 00017 */ 00018 00019 #include "entryloader.h" 00020 00021 #include "entryhandler.h" 00022 #include "feed.h" 00023 00024 #include <QtCore/QByteArray> 00025 00026 #include <kconfig.h> 00027 #include <kdebug.h> 00028 #include <kio/job.h> 00029 #include <klocale.h> 00030 00031 using namespace KNS; 00032 00033 EntryLoader::EntryLoader(QObject* parent) 00034 : QObject(parent) 00035 { 00036 m_feed = 0; 00037 m_provider = 0; 00038 } 00039 00040 void EntryLoader::load(const Provider *provider, Feed *feed) 00041 { 00042 //kDebug() << "EntryLoader::load()"; 00043 00044 m_provider = provider; 00045 m_feed = feed; 00046 00047 m_entries.clear(); 00048 m_jobdata.clear(); 00049 00050 KUrl stuffurl = feed->feedUrl(); 00051 //kDebug() << "EntryLoader::load(): stuffUrl: " << stuffurl.url(); 00052 00053 KIO::TransferJob *job = KIO::get(stuffurl, KIO::NoReload, KIO::HideProgressInfo); 00054 connect(job, SIGNAL(result(KJob *)), 00055 SLOT(slotJobResult(KJob *))); 00056 connect(job, SIGNAL(data(KIO::Job *, const QByteArray &)), 00057 SLOT(slotJobData(KIO::Job *, const QByteArray &))); 00058 connect(job, SIGNAL(percent(KJob*, unsigned long)), 00059 this, SIGNAL(signalProgress(KJob*, unsigned long))); 00060 } 00061 00062 Feed *EntryLoader::feed() const 00063 { 00064 return m_feed; 00065 } 00066 00067 const Provider *EntryLoader::provider() const 00068 { 00069 return m_provider; 00070 } 00071 00072 void EntryLoader::slotJobData(KIO::Job *, const QByteArray &data) 00073 { 00074 //kDebug(550) << "EntryLoader::slotJobData()"; 00075 00076 m_jobdata.append(data); 00077 } 00078 00079 void EntryLoader::slotJobResult(KJob *job) 00080 { 00081 if (job->error()) { 00082 emit signalEntriesFailed(); 00083 return; 00084 } 00085 00086 //QString contents = QString::fromUtf8(m_jobdata); 00087 00088 //kDebug() << "--ENTRIES-START--"; 00089 //kDebug() << QString::fromUtf8(m_jobdata); 00090 //kDebug() << "--ENTRIES-END--"; 00091 00092 QDomDocument doc; 00093 if (!doc.setContent(m_jobdata)) { 00094 emit signalEntriesFailed(); 00095 return; 00096 } 00097 00098 QDomElement entries = doc.documentElement(); 00099 00100 if (entries.isNull()) { 00101 kWarning() << "No document in stuff.xml."; 00102 } 00103 00104 QDomNode n; 00105 for (n = entries.firstChild(); !n.isNull(); n = n.nextSibling()) { 00106 QDomElement e = n.toElement(); 00107 00108 if (e.tagName() == "stuff") { 00109 EntryHandler handler(e); 00110 Entry * entry = handler.entryptr(); 00111 m_entries.append(entry); 00112 m_feed->addEntry(entry); 00113 //kDebug() << " entry " << entry->name().representation() << " loaded from provider"; 00114 } 00115 } 00116 00117 emit signalEntriesLoaded(m_entries); 00118 } 00119 00120 #include "entryloader.moc"
KDE 4.6 API Reference