• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepimlibs API Reference
  • KDE Home
  • Contact Us
 

KXMLRPC Client Library

  • sources
  • kde-4.14
  • kdepimlibs
  • kxmlrpcclient
client.cpp
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright (C) 2003 - 2004 by Frerich Raabe <raabe@kde.org> *
3  * Tobias Koenig <tokoe@kde.org> *
4  * Copyright (C) 2006 by Narayan Newton <narayannewton@gmail.com> *
5  * *
6  * This program is distributed in the hope that it will be useful, but *
7  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
8  * or FITNESS FOR A PARTICULAR PURPOSE. For licensing and distribution *
9  * details, check the accompanying file 'COPYING.BSD'. *
10  *****************************************************************************/
24 #include "client.h"
25 #include "query.h"
26 
27 #include <kio/job.h>
28 #include <kdebug.h>
29 
30 #include <QtCore/QVariant>
31 
32 using namespace KXmlRpc;
33 
34 class Client::Private
35 {
36  public:
37  Private() : mUserAgent( "KDE XMLRPC resources" ), mDigestAuth( false ){}
38 
39  void queryFinished( Query * );
40 
41  KUrl mUrl;
42  QString mUserAgent;
43  bool mDigestAuth;
44  QList<Query*> mPendingQueries;
45 };
46 
47 void Client::Private::queryFinished( Query *query )
48 {
49  mPendingQueries.removeAll( query );
50  query->deleteLater();
51 }
52 
53 Client::Client( QObject *parent )
54  : QObject( parent ), d( new Private )
55 {
56 }
57 
58 Client::Client( const KUrl &url, QObject *parent )
59  : QObject( parent ), d( new Private )
60 {
61  d->mUrl = url;
62 }
63 
64 Client::~Client()
65 {
66  QList<Query *>::Iterator it;
67  for ( it = d->mPendingQueries.begin(); it != d->mPendingQueries.end(); ++it ) {
68  ( *it )->deleteLater();
69  }
70 
71  d->mPendingQueries.clear();
72 
73  delete d;
74 }
75 
76 void Client::setUrl( const KUrl &url )
77 {
78  d->mUrl = url.isValid() ? url : KUrl();
79 }
80 
81 KUrl Client::url() const
82 {
83  return d->mUrl;
84 }
85 
86 QString Client::userAgent() const
87 {
88  return d->mUserAgent;
89 }
90 
91 void Client::setUserAgent( const QString &userAgent )
92 {
93  d->mUserAgent = userAgent;
94 }
95 
96 bool Client::isDigestAuthEnabled() const
97 {
98  return d->mDigestAuth;
99 }
100 
101 void Client::setDigestAuthEnabled( bool enabled )
102 {
103  d->mDigestAuth = enabled;
104 }
105 
106 void Client::call( const QString &method, const QList<QVariant> &args,
107  QObject *msgObj, const char *messageSlot,
108  QObject *faultObj, const char *faultSlot, const QVariant &id )
109 {
110 
111  QMap<QString, QString> metaData;
112 
113  if ( d->mUrl.isEmpty() ) {
114  kWarning() << "Cannot execute call to" << method << ": empty server URL";
115  }
116 
117  //Fill metadata, with userAgent and possible digest auth
118  if ( d->mUserAgent.isEmpty() ) {
119  metaData["UserAgent"] = "KDE-XMLRPC";
120  } else {
121  metaData["UserAgent"] = d->mUserAgent;
122  }
123 
124  if ( d->mDigestAuth ) {
125  metaData["WWW-Authenticate:"] = "Digest";
126  }
127 
128  Query *query = Query::create( id, this );
129  connect( query, SIGNAL(message(QList<QVariant>,QVariant)), msgObj, messageSlot );
130  connect( query, SIGNAL(fault(int,QString,QVariant)), faultObj, faultSlot );
131  connect( query, SIGNAL(finished(Query*)), this, SLOT(queryFinished(Query*)) );
132  d->mPendingQueries.append( query );
133 
134  query->call( d->mUrl.url(), method, args, metaData );
135 }
136 
137 void Client::call( const QString &method, const QVariant &arg,
138  QObject *msgObj, const char *messageSlot,
139  QObject *faultObj, const char *faultSlot,
140  const QVariant &id )
141 {
142  QList<QVariant> args;
143  args << arg ;
144  call( method, args, msgObj, messageSlot, faultObj, faultSlot, id );
145 }
146 
147 void Client::call( const QString &method, int arg,
148  QObject *msgObj, const char *messageSlot,
149  QObject *faultObj, const char *faultSlot,
150  const QVariant &id )
151 {
152  QList<QVariant> args;
153  args << QVariant( arg );
154  call( method, args, msgObj, messageSlot, faultObj, faultSlot, id );
155 }
156 
157 void Client::call( const QString &method, bool arg,
158  QObject *msgObj, const char *messageSlot,
159  QObject *faultObj, const char *faultSlot,
160  const QVariant &id )
161 {
162  QList<QVariant> args;
163  args << QVariant( arg );
164  call( method, args, msgObj, messageSlot, faultObj, faultSlot, id );
165 }
166 
167 void Client::call( const QString &method, double arg,
168  QObject *msgObj, const char *messageSlot,
169  QObject *faultObj, const char *faultSlot,
170  const QVariant &id )
171 {
172  QList<QVariant> args;
173  args << QVariant( arg );
174  call( method, args, msgObj, messageSlot, faultObj, faultSlot, id );
175 }
176 
177 void Client::call( const QString &method, const QString &arg,
178  QObject *msgObj, const char *messageSlot,
179  QObject *faultObj, const char *faultSlot,
180  const QVariant &id )
181 {
182  QList<QVariant> args;
183  args << QVariant( arg );
184  call( method, args, msgObj, messageSlot, faultObj, faultSlot, id );
185 }
186 
187 void Client::call( const QString &method, const QByteArray &arg,
188  QObject *msgObj, const char *messageSlot,
189  QObject *faultObj, const char *faultSlot,
190  const QVariant &id )
191 {
192  QList<QVariant> args;
193  args << QVariant( arg );
194  call( method, args, msgObj, messageSlot, faultObj, faultSlot, id );
195 }
196 
197 void Client::call( const QString &method, const QDateTime &arg,
198  QObject *msgObj, const char *messageSlot,
199  QObject *faultObj, const char *faultSlot,
200  const QVariant &id )
201 {
202  QList<QVariant> args;
203  args << QVariant( arg );
204  call( method, args, msgObj, messageSlot, faultObj, faultSlot, id );
205 }
206 
207 void Client::call( const QString &method, const QStringList &arg,
208  QObject *msgObj, const char *messageSlot,
209  QObject *faultObj, const char *faultSlot,
210  const QVariant &id )
211 {
212  QList<QVariant> args;
213  for ( int i = 0; i < arg.count(); ++i ) {
214  args << QVariant( arg[ i ] );
215  }
216 
217  call( method, args, msgObj, messageSlot, faultObj, faultSlot, id );
218 }
219 
220 #include "moc_client.cpp"
QByteArray
KXmlRpc::Client::setDigestAuthEnabled
void setDigestAuthEnabled(bool enabled)
Enables/disables HTTP-Digest authentication.
Definition: client.cpp:101
KXmlRpc::Client::call
void call(const QString &method, const QList< QVariant > &args, QObject *msgObj, const char *messageSlot, QObject *faultObj, const char *faultSlot, const QVariant &id=QVariant())
Calls the given method on a XML-RPC server, with the given argument list.
Definition: client.cpp:106
QMap
KXmlRpc::Client::isDigestAuthEnabled
bool isDigestAuthEnabled() const
Returns true if HTTP-Digest authentication is enabled, false if not.
Definition: client.cpp:96
KXmlRpc::Client::setUserAgent
void setUserAgent(const QString &userAgent)
Sets the userAgent string the Client will use to identify itself.
Definition: client.cpp:91
KXmlRpc::Client::Client
Client(QObject *parent=0)
Constructs a XML-RPC Client.
Definition: client.cpp:53
query.h
This file is part of KXmlRpc and defines our internal classes.
KXmlRpc::Query
Query is a class that represents an individual XML-RPC call.
Definition: query.h:44
QList::count
int count(const T &value) const
QObject
QList::removeAll
int removeAll(const T &value)
QObject::deleteLater
void deleteLater()
QString
QList
QStringList
KXmlRpc::Query::call
void call(const QString &server, const QString &method, const QList< QVariant > &args, const QMap< QString, QString > &jobMetaData)
Calls the specified method on the specified server with the given argument list.
Definition: query.cpp:400
KXmlRpc::Client::url
KUrl url() const
Returns the current url the XML-RPC Client will connect to.
Definition: client.cpp:81
client.h
This file is part of the API for accessing XML-RPC Servers and defines the Client class...
KXmlRpc::Query::create
static Query * create(const QVariant &id=QVariant(), QObject *parent=0)
Constructs a query.
Definition: query.cpp:395
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
KXmlRpc::Client::userAgent
QString userAgent() const
Returns the user agent string currently used by the Client.
Definition: client.cpp:86
KXmlRpc::Client::setUrl
void setUrl(const KUrl &url)
Sets the url the Client will connect to.
Definition: client.cpp:76
QDateTime
KXmlRpc::Client::~Client
~Client()
Destroys the XML-RPC Client.
Definition: client.cpp:64
QVariant
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:37:28 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KXMLRPC Client Library

Skip menu "KXMLRPC Client Library"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2

Search



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