• 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.12
  • 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 #include <klocalizedstring.h>
30 #include <kurl.h>
31 
32 #include <QtCore/QVariant>
33 
34 using namespace KXmlRpc;
35 
36 class Client::Private
37 {
38  public:
39  Private() : mUserAgent( "KDE XMLRPC resources" ), mDigestAuth( false ){}
40 
41  void queryFinished( Query * );
42 
43  KUrl mUrl;
44  QString mUserAgent;
45  bool mDigestAuth;
46  QList<Query*> mPendingQueries;
47 };
48 
49 void Client::Private::queryFinished( Query *query )
50 {
51  mPendingQueries.removeAll( query );
52  query->deleteLater();
53 }
54 
55 Client::Client( QObject *parent )
56  : QObject( parent ), d( new Private )
57 {
58 }
59 
60 Client::Client( const KUrl &url, QObject *parent )
61  : QObject( parent ), d( new Private )
62 {
63  d->mUrl = url;
64 }
65 
66 Client::~Client()
67 {
68  QList<Query *>::Iterator it;
69  for ( it = d->mPendingQueries.begin(); it != d->mPendingQueries.end(); ++it ) {
70  ( *it )->deleteLater();
71  }
72 
73  d->mPendingQueries.clear();
74 
75  delete d;
76 }
77 
78 void Client::setUrl( const KUrl &url )
79 {
80  d->mUrl = url.isValid() ? url : KUrl();
81 }
82 
83 KUrl Client::url() const
84 {
85  return d->mUrl;
86 }
87 
88 QString Client::userAgent() const
89 {
90  return d->mUserAgent;
91 }
92 
93 void Client::setUserAgent( const QString &userAgent )
94 {
95  d->mUserAgent = userAgent;
96 }
97 
98 bool Client::isDigestAuthEnabled() const
99 {
100  return d->mDigestAuth;
101 }
102 
103 void Client::setDigestAuthEnabled( bool enabled )
104 {
105  d->mDigestAuth = enabled;
106 }
107 
108 void Client::call( const QString &method, const QList<QVariant> &args,
109  QObject *msgObj, const char *messageSlot,
110  QObject *faultObj, const char *faultSlot, const QVariant &id )
111 {
112 
113  QMap<QString, QString> metaData;
114 
115  if ( d->mUrl.isEmpty() ) {
116  kWarning() << "Cannot execute call to" << method << ": empty server URL";
117  }
118 
119  //Fill metadata, with userAgent and possible digest auth
120  if ( d->mUserAgent.isEmpty() ) {
121  metaData["UserAgent"] = "KDE-XMLRPC";
122  } else {
123  metaData["UserAgent"] = d->mUserAgent;
124  }
125 
126  if ( d->mDigestAuth ) {
127  metaData["WWW-Authenticate:"] = "Digest";
128  }
129 
130  Query *query = Query::create( id, this );
131  connect( query, SIGNAL(message(QList<QVariant>,QVariant)), msgObj, messageSlot );
132  connect( query, SIGNAL(fault(int,QString,QVariant)), faultObj, faultSlot );
133  connect( query, SIGNAL(finished(Query*)), this, SLOT(queryFinished(Query*)) );
134  d->mPendingQueries.append( query );
135 
136  query->call( d->mUrl.url(), method, args, metaData );
137 }
138 
139 void Client::call( const QString &method, const QVariant &arg,
140  QObject *msgObj, const char *messageSlot,
141  QObject *faultObj, const char *faultSlot,
142  const QVariant &id )
143 {
144  QList<QVariant> args;
145  args << arg ;
146  call( method, args, msgObj, messageSlot, faultObj, faultSlot, id );
147 }
148 
149 void Client::call( const QString &method, int arg,
150  QObject *msgObj, const char *messageSlot,
151  QObject *faultObj, const char *faultSlot,
152  const QVariant &id )
153 {
154  QList<QVariant> args;
155  args << QVariant( arg );
156  call( method, args, msgObj, messageSlot, faultObj, faultSlot, id );
157 }
158 
159 void Client::call( const QString &method, bool arg,
160  QObject *msgObj, const char *messageSlot,
161  QObject *faultObj, const char *faultSlot,
162  const QVariant &id )
163 {
164  QList<QVariant> args;
165  args << QVariant( arg );
166  call( method, args, msgObj, messageSlot, faultObj, faultSlot, id );
167 }
168 
169 void Client::call( const QString &method, double arg,
170  QObject *msgObj, const char *messageSlot,
171  QObject *faultObj, const char *faultSlot,
172  const QVariant &id )
173 {
174  QList<QVariant> args;
175  args << QVariant( arg );
176  call( method, args, msgObj, messageSlot, faultObj, faultSlot, id );
177 }
178 
179 void Client::call( const QString &method, const QString &arg,
180  QObject *msgObj, const char *messageSlot,
181  QObject *faultObj, const char *faultSlot,
182  const QVariant &id )
183 {
184  QList<QVariant> args;
185  args << QVariant( arg );
186  call( method, args, msgObj, messageSlot, faultObj, faultSlot, id );
187 }
188 
189 void Client::call( const QString &method, const QByteArray &arg,
190  QObject *msgObj, const char *messageSlot,
191  QObject *faultObj, const char *faultSlot,
192  const QVariant &id )
193 {
194  QList<QVariant> args;
195  args << QVariant( arg );
196  call( method, args, msgObj, messageSlot, faultObj, faultSlot, id );
197 }
198 
199 void Client::call( const QString &method, const QDateTime &arg,
200  QObject *msgObj, const char *messageSlot,
201  QObject *faultObj, const char *faultSlot,
202  const QVariant &id )
203 {
204  QList<QVariant> args;
205  args << QVariant( arg );
206  call( method, args, msgObj, messageSlot, faultObj, faultSlot, id );
207 }
208 
209 void Client::call( const QString &method, const QStringList &arg,
210  QObject *msgObj, const char *messageSlot,
211  QObject *faultObj, const char *faultSlot,
212  const QVariant &id )
213 {
214  QList<QVariant> args;
215  for ( int i = 0; i < arg.count(); ++i ) {
216  args << QVariant( arg[ i ] );
217  }
218 
219  call( method, args, msgObj, messageSlot, faultObj, faultSlot, id );
220 }
221 
222 #include "moc_client.cpp"
KXmlRpc::Client::setDigestAuthEnabled
void setDigestAuthEnabled(bool enabled)
Enables/disables HTTP-Digest authentication.
Definition: client.cpp:103
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:108
KXmlRpc::Client::isDigestAuthEnabled
bool isDigestAuthEnabled() const
Returns true if HTTP-Digest authentication is enabled, false if not.
Definition: client.cpp:98
KXmlRpc::Client::setUserAgent
void setUserAgent(const QString &userAgent)
Sets the userAgent string the Client will use to identify itself.
Definition: client.cpp:93
KXmlRpc::Client::Client
Client(QObject *parent=0)
Constructs a XML-RPC Client.
Definition: client.cpp:55
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
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:83
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
KXmlRpc::Client::userAgent
QString userAgent() const
Returns the user agent string currently used by the Client.
Definition: client.cpp:88
KXmlRpc::Client::setUrl
void setUrl(const KUrl &url)
Sets the url the Client will connect to.
Definition: client.cpp:78
KXmlRpc::Client::~Client
~Client()
Destroys the XML-RPC Client.
Definition: client.cpp:66
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:17 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 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
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

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