KNewStuff
dxsengine.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 "dxsengine.h" 00020 00021 #include "dxs.h" 00022 00023 #include <knewstuff2/core/category.h> 00024 #include <kdebug.h> 00025 00026 using namespace KNS; 00027 00028 DxsEngine::DxsEngine(QObject* parent) 00029 : CoreEngine(parent), m_dxspolicy(DxsIfPossible) 00030 { 00031 } 00032 00033 DxsEngine::~DxsEngine() 00034 { 00035 } 00036 00037 void DxsEngine::setDxsPolicy(Policy policy) 00038 { 00039 m_dxspolicy = policy; 00040 } 00041 00042 // get the dxs object 00043 Dxs * DxsEngine::dxsObject(const Provider * provider) 00044 { 00045 return (m_dxsbyprovider.contains(provider) ? m_dxsbyprovider.value(provider) : NULL); 00046 } 00047 00048 void DxsEngine::loadEntries(Provider *provider) 00049 { 00051 // Ensure that the provider offers DXS at all 00052 // Match DXS offerings with the engine's policy 00053 if (provider->webService().isValid()) { 00054 if (m_dxspolicy == DxsNever) { 00055 CoreEngine::loadEntries(provider); 00056 return; 00057 } 00058 } else { 00059 if (m_dxspolicy != DxsAlways) { 00060 CoreEngine::loadEntries(provider); 00061 return; 00062 } else { 00063 kError() << "DxsEngine: DXS requested but not offered" << endl; 00064 return; 00065 } 00066 } 00067 00068 // From here on, it's all DXS now 00069 00070 if (!m_dxsbyprovider.contains(provider)) { 00071 Dxs * dxs = new Dxs(this, provider); 00072 dxs->setEndpoint(provider->webService()); 00073 // connect entries signal 00074 connect(dxs, SIGNAL(signalEntries(KNS::Entry::List, Feed*)), 00075 SLOT(slotEntriesLoadedDXS(KNS::Entry::List, Feed*))); 00076 // FIXME: which one of signalFault()/signalError()? Or both? 00077 connect(dxs, SIGNAL(signalFault()), 00078 SLOT(slotEntriesFailed())); 00079 // connect categories signal 00080 connect(dxs, SIGNAL(signalCategories(QList<KNS::Category*>)), 00081 SLOT(slotCategories(QList<KNS::Category*>))); 00082 m_dxsbyprovider.insert(provider, dxs); 00083 } 00084 00085 Dxs * dxs = m_dxsbyprovider.value(provider); 00086 00087 dxs->call_categories(); 00088 } 00089 00090 void DxsEngine::slotCategories(QList<KNS::Category*> categories) 00091 { 00092 Dxs * dxs = qobject_cast<Dxs*>(sender()); 00093 Provider * provider = dxs->provider(); 00094 00095 //kDebug() << "slot categories called for provider: " << provider->name().representation(); 00096 00097 for (QList<KNS::Category*>::iterator it = categories.begin(); it != categories.end(); ++it) { 00098 Category *category = (*it); 00099 QStringList feeds = provider->feeds(); 00100 for (int i = 0; i < feeds.size(); ++i) { 00101 dxs->call_entries(category->id(), feeds.at(i)); 00102 } 00103 } 00104 } 00105 00106 void DxsEngine::slotEntriesLoadedDXS(KNS::Entry::List list, Feed * feed) 00107 { 00108 Dxs * dxs = qobject_cast<Dxs*>(sender()); 00109 Provider * provider = dxs->provider(); 00110 00111 mergeEntries(list, feed, provider); 00112 } 00113 00114 void DxsEngine::slotEntriesFailed() 00115 { 00116 emit signalEntriesFailed(); 00117 } 00118 00119 #include "dxsengine.moc"
KDE 4.6 API Reference