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