KNewStuff
dxs.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 "dxs.h" 00020 00021 #include "soap.h" 00022 00023 #include "knewstuff2/core/entry.h" 00024 #include "knewstuff2/core/entryhandler.h" 00025 #include "knewstuff2/core/category.h" 00026 #include "knewstuff2/core/provider.h" 00027 00028 #include <kdebug.h> 00029 00030 #include <QtXml/qdom.h> 00031 #include <QtCore/QMutableStringListIterator> 00032 00033 using namespace KNS; 00034 00035 Dxs::Dxs(QObject* parent, KNS::Provider * provider) 00036 : QObject(parent), m_provider(provider) 00037 { 00038 m_soap = new Soap(this); 00039 connect(m_soap, SIGNAL(signalResult(QDomNode, int)), SLOT(slotResult(QDomNode, int))); 00040 connect(m_soap, SIGNAL(signalError()), SLOT(slotError())); 00041 } 00042 00043 Dxs::~Dxs() 00044 { 00045 } 00046 00047 Provider * Dxs::provider() 00048 { 00049 return m_provider; 00050 } 00051 00052 void Dxs::setEndpoint(KUrl endpoint) 00053 { 00054 m_endpoint = endpoint; 00055 } 00056 00057 void Dxs::call_info() 00058 { 00059 QDomDocument doc; 00060 QDomElement info = doc.createElement("ns:GHNSInfo"); 00061 //QDomText t = doc.createTextNode("text"); 00062 //check.appendChild(t); 00063 m_soap->call(info, m_endpoint.url()); 00064 } 00065 00066 void Dxs::call_categories() 00067 { 00068 QDomDocument doc; 00069 QDomElement info = doc.createElement("ns:GHNSCategories"); 00070 m_soap->call(info, m_endpoint.url()); 00071 } 00072 00073 void Dxs::call_entries(QString category, QString feed) 00074 { 00075 //kDebug() << "calling entries on category " << category << " and feed " << feed; 00076 QDomDocument doc; 00077 QDomElement entries = doc.createElement("ns:GHNSList"); 00078 QDomElement ecategory = doc.createElement("category"); 00079 QDomText t = doc.createTextNode(category); 00080 ecategory.appendChild(t); 00081 entries.appendChild(ecategory); 00082 if (!feed.isEmpty()) { 00083 QDomElement efeed = doc.createElement("feed"); 00084 QDomText t2 = doc.createTextNode(feed); 00085 efeed.appendChild(t2); 00086 entries.appendChild(efeed); 00087 } 00088 int jobid = m_soap->call(entries, m_endpoint.url()); 00089 m_jobfeeds.insert(jobid, m_provider->downloadUrlFeed(feed)); 00090 } 00091 00092 void Dxs::call_comments(int id) 00093 { 00094 //kDebug() << "getting comments for entry: " << id; 00095 QDomDocument doc; 00096 QDomElement comments = doc.createElement("ns:GHNSComments"); 00097 QDomElement eid = doc.createElement("id"); 00098 QDomText t = doc.createTextNode(QString::number(id)); 00099 eid.appendChild(t); 00100 comments.appendChild(eid); 00101 m_soap->call(comments, m_endpoint.url()); 00102 } 00103 00104 void Dxs::call_changes(int id) 00105 { 00106 QDomDocument doc; 00107 QDomElement changes = doc.createElement("ns:GHNSChanges"); 00108 QDomElement eid = doc.createElement("id"); 00109 QDomText t = doc.createTextNode(QString::number(id)); 00110 eid.appendChild(t); 00111 changes.appendChild(eid); 00112 m_soap->call(changes, m_endpoint.url()); 00113 } 00114 00115 void Dxs::call_history(int id) 00116 { 00117 QDomDocument doc; 00118 QDomElement history = doc.createElement("ns:GHNSHistory"); 00119 QDomElement eid = doc.createElement("id"); 00120 QDomText t = doc.createTextNode(QString::number(id)); 00121 eid.appendChild(t); 00122 history.appendChild(eid); 00123 m_soap->call(history, m_endpoint.url()); 00124 } 00125 00126 void Dxs::call_removal(int id) 00127 { 00128 QDomDocument doc; 00129 QDomElement removal = doc.createElement("ns:GHNSRemoval"); 00130 QDomElement eid = doc.createElement("id"); 00131 QDomText t = doc.createTextNode(QString::number(id)); 00132 eid.appendChild(t); 00133 removal.appendChild(eid); 00134 m_soap->call(removal, m_endpoint.url()); 00135 } 00136 00137 void Dxs::call_subscription(int id, bool subscribe) 00138 { 00139 QDomDocument doc; 00140 QDomElement subscription = doc.createElement("ns:GHNSSubscription"); 00141 QDomElement eid = doc.createElement("id"); 00142 QDomText t = doc.createTextNode(QString::number(id)); 00143 eid.appendChild(t); 00144 subscription.appendChild(eid); 00145 QDomElement esubscribe = doc.createElement("subscribe"); 00146 QDomText t2 = doc.createTextNode((subscribe ? "true" : "false")); 00147 esubscribe.appendChild(t2); 00148 subscription.appendChild(esubscribe); 00149 m_soap->call(subscription, m_endpoint.url()); 00150 } 00151 00152 void Dxs::call_comment(int id, QString comment) 00153 { 00154 //kDebug() << "setting comment: " << comment << " for entry: " << id; 00155 QDomDocument doc; 00156 QDomElement ecomment = doc.createElement("ns:GHNSComment"); 00157 QDomElement eid = doc.createElement("id"); 00158 QDomText tid = doc.createTextNode(QString::number(id)); 00159 eid.appendChild(tid); 00160 ecomment.appendChild(eid); 00161 QDomElement ecommenttext = doc.createElement("comment"); 00162 QDomText tcomment = doc.createTextNode(comment); 00163 ecommenttext.appendChild(tcomment); 00164 ecomment.appendChild(ecommenttext); 00165 m_soap->call(ecomment, m_endpoint.url()); 00166 } 00167 00168 void Dxs::call_rating(int id, int rating) 00169 { 00170 QDomDocument doc; 00171 QDomElement erating = doc.createElement("ns:GHNSRating"); 00172 QDomElement eid = doc.createElement("id"); 00173 QDomText tid = doc.createTextNode(QString::number(id)); 00174 eid.appendChild(tid); 00175 erating.appendChild(eid); 00176 QDomElement eratingtext = doc.createElement("rating"); 00177 QDomText trating = doc.createTextNode(QString::number(rating)); 00178 eratingtext.appendChild(trating); 00179 erating.appendChild(eratingtext); 00180 m_soap->call(erating, m_endpoint.url()); 00181 } 00182 00183 void Dxs::slotError() 00184 { 00185 emit signalError(); 00186 } 00187 00188 void Dxs::slotResult(QDomNode node, int jobid) 00189 { 00190 //kDebug() << "LOCALNAME: " << m_soap->localname(node); 00191 00192 bool success = true; 00193 if (m_soap->localname(node) == "Fault") { 00194 success = false; 00195 emit signalFault(); 00196 return; 00197 } 00198 00199 if (m_soap->localname(node) == "GHNSInfoResponse") { 00200 QString provider = m_soap->xpath(node, "/provider"); 00201 QString server = m_soap->xpath(node, "/server"); 00202 QString version = m_soap->xpath(node, "/version"); 00203 00204 emit signalInfo(provider, server, version); 00205 } else if (m_soap->localname(node) == "GHNSCategoriesResponse") { 00206 QList<KNS::Category*> categories; 00207 00208 QList<QDomNode> catlist = m_soap->directChildNodes(node, "category"); 00209 for (int i = 0; i < catlist.count(); i++) { 00210 KNS::Category *category = new KNS::Category(); 00211 00212 QDomNode node = catlist.at(i).toElement(); 00213 QString categoryname = m_soap->xpath(node, "/category"); 00214 QString icon = m_soap->xpath(node, "/icon"); 00215 QString name = m_soap->xpath(node, "/name"); 00216 QString description = m_soap->xpath(node, "/description"); 00217 00218 category->setId(categoryname); 00219 category->setName(name); 00220 category->setIcon(icon); 00221 category->setDescription(description); 00222 00223 categories << category; 00224 } 00225 00226 emit signalCategories(categories); 00227 } else if (m_soap->localname(node) == "GHNSListResponse") { 00228 QList<KNS::Entry*> entries; 00229 00230 Feed * thisFeed = m_jobfeeds.value(jobid); 00231 QDomNode entriesNode = node.firstChild(); 00232 // FIXME: find a way to put a real assertion in here to ensure the entriesNode is the "entries" node 00233 //Q_ASSERT(entriesNode.localName() == "entries"); 00234 00235 QList<QDomNode> entrylist = m_soap->directChildNodes(entriesNode, "entry"); 00236 for (int i = 0; i < entrylist.count(); i++) { 00237 QDomElement element = entrylist.at(i).toElement(); 00238 element.setTagName("stuff"); 00239 KNS::EntryHandler handler(element); 00240 KNS::Entry *entry = handler.entryptr(); 00241 00242 entries << entry; 00243 thisFeed->addEntry(entry); 00244 //kDebug() << "ENTRY: " << entry->name().representation() << " location: " << entry->payload().representation(); 00245 } 00246 00247 emit signalEntries(entries, thisFeed); 00248 } else if (m_soap->localname(node) == "GHNSCommentsResponse") { 00249 QStringList comments; 00250 00251 QList<QDomNode> comlist = m_soap->directChildNodes(node, "comments"); 00252 for (int i = 0; i < comlist.count(); i++) { 00253 comments << comlist.at(i).toElement().text(); 00254 } 00255 00256 emit signalComments(comments); 00257 } else if (m_soap->localname(node) == "GHNSChangesResponse") { 00258 QStringList changes; 00259 00260 QList<QDomNode> changelist = m_soap->directChildNodes(node, "entry"); 00261 for (int i = 0; i < changelist.count(); i++) { 00262 QDomNode node = changelist.at(i); 00263 00264 QString version = m_soap->xpath(node, "/version"); 00265 QString changelog = m_soap->xpath(node, "/changelog"); 00266 //kDebug() << "CHANGELOG: " << version << " " << changelog; 00267 00268 changes << changelog; 00269 } 00270 00271 // FIXME: pass (version, changelog) pairs - Python I miss you :-) 00272 emit signalChanges(changes); 00273 } else if (m_soap->localname(node) == "GHNSHistoryResponse") { 00274 QStringList entries; 00275 00276 QList<QDomNode> entrylist = m_soap->directChildNodes(node, "entry"); 00277 for (int i = 0; i < entrylist.count(); i++) { 00278 entries << entrylist.at(i).toElement().text(); 00279 } 00280 00281 emit signalHistory(entries); 00282 } else if (m_soap->localname(node) == "GHNSRemovalResponse") { 00283 emit signalRemoval(success); 00284 } else if (m_soap->localname(node) == "GHNSSubscriptionResponse") { 00285 emit signalSubscription(success); 00286 } else if (m_soap->localname(node) == "GHNSCommentResponse") { 00287 emit signalComment(success); 00288 } else if (m_soap->localname(node) == "GHNSRatingResponse") { 00289 emit signalRating(success); 00290 } 00291 } 00292 00293 #include "dxs.moc"
KDE 4.6 API Reference