KNewStuff
providerloader.cpp
Go to the documentation of this file.00001 /* 00002 This file is part of KNewStuff2. 00003 Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org> 00004 Copyright (c) 2003 - 2007 Josef Spillner <spillner@kde.org> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 Boston, MA 02110-1301, USA. 00020 */ 00021 00022 #include "providerloader.h" 00023 00024 #include "providerhandler.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 ProviderLoader::ProviderLoader(QObject* parent) 00036 : QObject(parent) 00037 { 00038 } 00039 00040 void ProviderLoader::load(const QString &providersurl) 00041 { 00042 //kDebug(550) << "ProviderLoader::load()"; 00043 00044 m_providers.clear(); 00045 m_jobdata.clear(); 00046 00047 //kDebug(550) << "ProviderLoader::load(): providersUrl: " << providersurl; 00048 00049 KIO::TransferJob *job = KIO::get(KUrl(providersurl), KIO::NoReload, KIO::HideProgressInfo); 00050 connect(job, SIGNAL(result(KJob *)), 00051 SLOT(slotJobResult(KJob *))); 00052 connect(job, SIGNAL(data(KIO::Job *, const QByteArray &)), 00053 SLOT(slotJobData(KIO::Job *, const QByteArray &))); 00054 } 00055 00056 void ProviderLoader::slotJobData(KIO::Job *, const QByteArray &data) 00057 { 00058 //kDebug(550) << "ProviderLoader::slotJobData()"; 00059 00060 m_jobdata.append(data); 00061 } 00062 00063 void ProviderLoader::slotJobResult(KJob *job) 00064 { 00065 if (job->error()) { 00066 emit signalProvidersFailed(); 00067 return; 00068 } 00069 00070 //kDebug(550) << "--PROVIDERS-START--"; 00071 //kDebug(550) << QString::fromUtf8(m_jobdata); 00072 //kDebug(550) << "--PROVIDERS-END--"; 00073 00074 QDomDocument doc; 00075 if (!doc.setContent(m_jobdata)) { 00076 emit signalProvidersFailed(); 00077 return; 00078 } 00079 00080 QDomElement providers = doc.documentElement(); 00081 00082 if (providers.tagName() != "ghnsproviders" && 00083 providers.tagName() != "knewstuffproviders") { 00084 kWarning(550) << "No document in providers.xml."; 00085 emit signalProvidersFailed(); 00086 return; 00087 } 00088 00089 QDomNode n; 00090 for (n = providers.firstChild(); !n.isNull(); n = n.nextSibling()) { 00091 QDomElement p = n.toElement(); 00092 00093 if (p.tagName() == "provider") { 00094 ProviderHandler handler(p); 00095 m_providers.append(handler.providerptr()); 00096 } 00097 } 00098 00099 emit signalProvidersLoaded(m_providers); 00100 } 00101 00102 #include "providerloader.moc"