• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KNewStuff

  • knewstuff
  • knewstuff2
  • dxs
dxs.cpp
Go to the documentation of this file.
1/*
2 This file is part of KNewStuff2.
3 Copyright (c) 2007 Josef Spillner <spillner@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19#include "dxs.h"
20
21#include "soap.h"
22
23#include "knewstuff2/core/entry.h"
24#include "knewstuff2/core/entryhandler.h"
25#include "knewstuff2/core/category.h"
26#include "knewstuff2/core/provider.h"
27
28#include <kdebug.h>
29
30#include <QtXml/qdom.h>
31#include <QtCore/QMutableStringListIterator>
32
33using namespace KNS;
34
35Dxs::Dxs(QObject* parent, KNS::Provider * provider)
36 : QObject(parent), m_provider(provider)
37{
38 m_soap = new Soap(this);
39 connect(m_soap, SIGNAL(signalResult(QDomNode,int)), SLOT(slotResult(QDomNode,int)));
40 connect(m_soap, SIGNAL(signalError()), SLOT(slotError()));
41}
42
43Dxs::~Dxs()
44{
45}
46
47Provider * Dxs::provider()
48{
49 return m_provider;
50}
51
52void Dxs::setEndpoint(KUrl endpoint)
53{
54 m_endpoint = endpoint;
55}
56
57void Dxs::call_info()
58{
59 QDomDocument doc;
60 QDomElement info = doc.createElement("ns:GHNSInfo");
61 //QDomText t = doc.createTextNode("text");
62 //check.appendChild(t);
63 m_soap->call(info, m_endpoint.url());
64}
65
66void Dxs::call_categories()
67{
68 QDomDocument doc;
69 QDomElement info = doc.createElement("ns:GHNSCategories");
70 m_soap->call(info, m_endpoint.url());
71}
72
73void Dxs::call_entries(QString category, QString feed)
74{
75 //kDebug() << "calling entries on category " << category << " and feed " << feed;
76 QDomDocument doc;
77 QDomElement entries = doc.createElement("ns:GHNSList");
78 QDomElement ecategory = doc.createElement("category");
79 QDomText t = doc.createTextNode(category);
80 ecategory.appendChild(t);
81 entries.appendChild(ecategory);
82 if (!feed.isEmpty()) {
83 QDomElement efeed = doc.createElement("feed");
84 QDomText t2 = doc.createTextNode(feed);
85 efeed.appendChild(t2);
86 entries.appendChild(efeed);
87 }
88 int jobid = m_soap->call(entries, m_endpoint.url());
89 m_jobfeeds.insert(jobid, m_provider->downloadUrlFeed(feed));
90}
91
92void Dxs::call_comments(int id)
93{
94 //kDebug() << "getting comments for entry: " << id;
95 QDomDocument doc;
96 QDomElement comments = doc.createElement("ns:GHNSComments");
97 QDomElement eid = doc.createElement("id");
98 QDomText t = doc.createTextNode(QString::number(id));
99 eid.appendChild(t);
100 comments.appendChild(eid);
101 m_soap->call(comments, m_endpoint.url());
102}
103
104void Dxs::call_changes(int id)
105{
106 QDomDocument doc;
107 QDomElement changes = doc.createElement("ns:GHNSChanges");
108 QDomElement eid = doc.createElement("id");
109 QDomText t = doc.createTextNode(QString::number(id));
110 eid.appendChild(t);
111 changes.appendChild(eid);
112 m_soap->call(changes, m_endpoint.url());
113}
114
115void Dxs::call_history(int id)
116{
117 QDomDocument doc;
118 QDomElement history = doc.createElement("ns:GHNSHistory");
119 QDomElement eid = doc.createElement("id");
120 QDomText t = doc.createTextNode(QString::number(id));
121 eid.appendChild(t);
122 history.appendChild(eid);
123 m_soap->call(history, m_endpoint.url());
124}
125
126void Dxs::call_removal(int id)
127{
128 QDomDocument doc;
129 QDomElement removal = doc.createElement("ns:GHNSRemoval");
130 QDomElement eid = doc.createElement("id");
131 QDomText t = doc.createTextNode(QString::number(id));
132 eid.appendChild(t);
133 removal.appendChild(eid);
134 m_soap->call(removal, m_endpoint.url());
135}
136
137void Dxs::call_subscription(int id, bool subscribe)
138{
139 QDomDocument doc;
140 QDomElement subscription = doc.createElement("ns:GHNSSubscription");
141 QDomElement eid = doc.createElement("id");
142 QDomText t = doc.createTextNode(QString::number(id));
143 eid.appendChild(t);
144 subscription.appendChild(eid);
145 QDomElement esubscribe = doc.createElement("subscribe");
146 QDomText t2 = doc.createTextNode((subscribe ? "true" : "false"));
147 esubscribe.appendChild(t2);
148 subscription.appendChild(esubscribe);
149 m_soap->call(subscription, m_endpoint.url());
150}
151
152void Dxs::call_comment(int id, QString comment)
153{
154 //kDebug() << "setting comment: " << comment << " for entry: " << id;
155 QDomDocument doc;
156 QDomElement ecomment = doc.createElement("ns:GHNSComment");
157 QDomElement eid = doc.createElement("id");
158 QDomText tid = doc.createTextNode(QString::number(id));
159 eid.appendChild(tid);
160 ecomment.appendChild(eid);
161 QDomElement ecommenttext = doc.createElement("comment");
162 QDomText tcomment = doc.createTextNode(comment);
163 ecommenttext.appendChild(tcomment);
164 ecomment.appendChild(ecommenttext);
165 m_soap->call(ecomment, m_endpoint.url());
166}
167
168void Dxs::call_rating(int id, int rating)
169{
170 QDomDocument doc;
171 QDomElement erating = doc.createElement("ns:GHNSRating");
172 QDomElement eid = doc.createElement("id");
173 QDomText tid = doc.createTextNode(QString::number(id));
174 eid.appendChild(tid);
175 erating.appendChild(eid);
176 QDomElement eratingtext = doc.createElement("rating");
177 QDomText trating = doc.createTextNode(QString::number(rating));
178 eratingtext.appendChild(trating);
179 erating.appendChild(eratingtext);
180 m_soap->call(erating, m_endpoint.url());
181}
182
183void Dxs::slotError()
184{
185 emit signalError();
186}
187
188void Dxs::slotResult(QDomNode node, int jobid)
189{
190 //kDebug() << "LOCALNAME: " << m_soap->localname(node);
191
192 bool success = true;
193 if (m_soap->localname(node) == "Fault") {
194 success = false;
195 emit signalFault();
196 return;
197 }
198
199 if (m_soap->localname(node) == "GHNSInfoResponse") {
200 QString provider = m_soap->xpath(node, "/provider");
201 QString server = m_soap->xpath(node, "/server");
202 QString version = m_soap->xpath(node, "/version");
203
204 emit signalInfo(provider, server, version);
205 } else if (m_soap->localname(node) == "GHNSCategoriesResponse") {
206 QList<KNS::Category*> categories;
207
208 QList<QDomNode> catlist = m_soap->directChildNodes(node, "category");
209 for (int i = 0; i < catlist.count(); i++) {
210 KNS::Category *category = new KNS::Category();
211
212 QDomNode node = catlist.at(i).toElement();
213 QString categoryname = m_soap->xpath(node, "/category");
214 QString icon = m_soap->xpath(node, "/icon");
215 QString name = m_soap->xpath(node, "/name");
216 QString description = m_soap->xpath(node, "/description");
217
218 category->setId(categoryname);
219 category->setName(name);
220 category->setIcon(icon);
221 category->setDescription(description);
222
223 categories << category;
224 }
225
226 emit signalCategories(categories);
227 } else if (m_soap->localname(node) == "GHNSListResponse") {
228 QList<KNS::Entry*> entries;
229
230 Feed * thisFeed = m_jobfeeds.value(jobid);
231 QDomNode entriesNode = node.firstChild();
232 // FIXME: find a way to put a real assertion in here to ensure the entriesNode is the "entries" node
233 //Q_ASSERT(entriesNode.localName() == "entries");
234
235 QList<QDomNode> entrylist = m_soap->directChildNodes(entriesNode, "entry");
236 for (int i = 0; i < entrylist.count(); i++) {
237 QDomElement element = entrylist.at(i).toElement();
238 element.setTagName("stuff");
239 KNS::EntryHandler handler(element);
240 KNS::Entry *entry = handler.entryptr();
241
242 entries << entry;
243 thisFeed->addEntry(entry);
244 //kDebug() << "ENTRY: " << entry->name().representation() << " location: " << entry->payload().representation();
245 }
246
247 emit signalEntries(entries, thisFeed);
248 } else if (m_soap->localname(node) == "GHNSCommentsResponse") {
249 QStringList comments;
250
251 QList<QDomNode> comlist = m_soap->directChildNodes(node, "comments");
252 for (int i = 0; i < comlist.count(); i++) {
253 comments << comlist.at(i).toElement().text();
254 }
255
256 emit signalComments(comments);
257 } else if (m_soap->localname(node) == "GHNSChangesResponse") {
258 QStringList changes;
259
260 QList<QDomNode> changelist = m_soap->directChildNodes(node, "entry");
261 for (int i = 0; i < changelist.count(); i++) {
262 QDomNode node = changelist.at(i);
263
264 QString version = m_soap->xpath(node, "/version");
265 QString changelog = m_soap->xpath(node, "/changelog");
266 //kDebug() << "CHANGELOG: " << version << " " << changelog;
267
268 changes << changelog;
269 }
270
271 // FIXME: pass (version, changelog) pairs - Python I miss you :-)
272 emit signalChanges(changes);
273 } else if (m_soap->localname(node) == "GHNSHistoryResponse") {
274 QStringList entries;
275
276 QList<QDomNode> entrylist = m_soap->directChildNodes(node, "entry");
277 for (int i = 0; i < entrylist.count(); i++) {
278 entries << entrylist.at(i).toElement().text();
279 }
280
281 emit signalHistory(entries);
282 } else if (m_soap->localname(node) == "GHNSRemovalResponse") {
283 emit signalRemoval(success);
284 } else if (m_soap->localname(node) == "GHNSSubscriptionResponse") {
285 emit signalSubscription(success);
286 } else if (m_soap->localname(node) == "GHNSCommentResponse") {
287 emit signalComment(success);
288 } else if (m_soap->localname(node) == "GHNSRatingResponse") {
289 emit signalRating(success);
290 }
291}
292
293#include "dxs.moc"
category.h
KNS::Category
KNewStuff category.
Definition: category.h:36
KNS::Category::setIcon
void setIcon(const KUrl &icon)
Sets the icon.
Definition: category.cpp:70
KNS::Category::setName
void setName(const KTranslatable &name)
Sets the name for this category.
Definition: category.cpp:50
KNS::Category::setDescription
void setDescription(const KTranslatable &type)
Sets the category description.
Definition: category.cpp:60
KNS::Category::setId
void setId(const QString &id)
Sets the unique id for this category.
Definition: category.cpp:40
KNS::Dxs::signalHistory
void signalHistory(QStringList entries)
KNS::Dxs::signalComment
void signalComment(bool success)
KNS::Dxs::call_rating
void call_rating(int id, int rating)
Definition: dxs.cpp:168
KNS::Dxs::call_entries
void call_entries(QString category, QString feed)
Definition: dxs.cpp:73
KNS::Dxs::provider
Provider * provider()
Definition: dxs.cpp:47
KNS::Dxs::signalRating
void signalRating(bool success)
KNS::Dxs::signalInfo
void signalInfo(QString provider, QString server, QString version)
KNS::Dxs::signalSubscription
void signalSubscription(bool success)
KNS::Dxs::signalRemoval
void signalRemoval(bool success)
KNS::Dxs::call_comments
void call_comments(int id)
Definition: dxs.cpp:92
KNS::Dxs::call_subscription
void call_subscription(int id, bool subscribe)
Definition: dxs.cpp:137
KNS::Dxs::signalError
void signalError()
KNS::Dxs::call_info
void call_info()
Definition: dxs.cpp:57
KNS::Dxs::call_categories
void call_categories()
Definition: dxs.cpp:66
KNS::Dxs::setEndpoint
void setEndpoint(KUrl endpoint)
Definition: dxs.cpp:52
KNS::Dxs::call_changes
void call_changes(int id)
Definition: dxs.cpp:104
KNS::Dxs::signalCategories
void signalCategories(QList< KNS::Category * > categories)
KNS::Dxs::signalFault
void signalFault()
KNS::Dxs::call_comment
void call_comment(int id, QString comment)
Definition: dxs.cpp:152
KNS::Dxs::signalComments
void signalComments(QStringList comments)
KNS::Dxs::Dxs
Dxs(QObject *parent, KNS::Provider *provider)
Definition: dxs.cpp:35
KNS::Dxs::call_history
void call_history(int id)
Definition: dxs.cpp:115
KNS::Dxs::signalChanges
void signalChanges(QStringList comments)
KNS::Dxs::signalEntries
void signalEntries(KNS::Entry::List entries, Feed *feed)
KNS::Dxs::~Dxs
~Dxs()
Definition: dxs.cpp:43
KNS::Dxs::call_removal
void call_removal(int id)
Definition: dxs.cpp:126
KNS::EntryHandler
Parser and dumper for KNewStuff data entries.
Definition: entryhandler.h:43
KNS::Entry
KNewStuff data entry container.
Definition: knewstuff2/core/entry.h:47
KNS::Feed
KNewStuff feed.
Definition: feed.h:46
KNS::Feed::addEntry
void addEntry(Entry *entry)
Adds an association to an entry.
Definition: feed.cpp:72
KNS::Provider
KNewStuff provider container.
Definition: knewstuff2/core/provider.h:52
KNS::Provider::downloadUrlFeed
Feed * downloadUrlFeed(const QString &feedtype) const
Feed to retrieve for the given feed type.
Definition: knewstuff2/core/provider.cpp:50
KNS::Soap
KNewStuff transport layer.
Definition: soap.h:51
KNS::Soap::localname
QString localname(const QDomNode &node)
Name of the QDomElement for node without the namespace.
Definition: soap.cpp:217
KNS::Soap::directChildNodes
QList< QDomNode > directChildNodes(const QDomNode &node, const QString &name)
Definition: soap.cpp:224
KNS::Soap::call
int call(const QDomElement &element, const QString &endpoint)
Send to the server - uses either soap or tree.
Definition: soap.cpp:47
KNS::Soap::xpath
QString xpath(const QDomNode &node, const QString &expr)
Find the text element to a xpath like expression.
Definition: soap.cpp:238
KUrl
KUrl::url
QString url(AdjustPathOption trailing=LeaveTrailingSlash) const
QList
QObject
dxs.h
entryhandler.h
kdebug.h
entry.h
provider.h
KNS
Definition: knewstuff2/core/author.h:27
name
const char * name(StandardAction id)
soap.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KNewStuff

Skip menu "KNewStuff"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal