25 #include "blogger1_p.h"
28 #include <kxmlrpcclient/client.h>
32 #include <KLocalizedString>
36 #include <QStringList>
38 using namespace KBlog;
41 :
Blog( server, *new Blogger1Private, parent )
48 :
Blog( server, dd, parent )
68 delete d->mXmlRpcClient;
69 d->mXmlRpcClient =
new KXmlRpc::Client( server );
70 d->mXmlRpcClient->setUserAgent(
userAgent() );
76 kDebug() <<
"Fetch user's info...";
78 d->mXmlRpcClient->call(
87 kDebug() <<
"Fetch List of Blogs...";
89 d->mXmlRpcClient->call(
98 kDebug() <<
"Fetching List of Posts...";
101 d->mXmlRpcClient->call(
102 d->getCallFromFunction( Blogger1Private::GetRecentPosts ), args,
104 this, SLOT(slotError(
int,
QString,QVariant)),
105 QVariant( number ) );
111 kError() <<
"Blogger1::modifyPost: post is null pointer";
116 kDebug() <<
"Fetching Post with url" << post->
postId();
118 unsigned int i= d->mCallCounter++;
119 d->mCallMap[ i ] = post;
120 d->mXmlRpcClient->call(
121 d->getCallFromFunction( Blogger1Private::FetchPost ), args,
132 kError() <<
"Blogger1::modifyPost: post is null pointer";
136 kDebug() <<
"Uploading Post with postId" << post->
postId();
137 unsigned int i= d->mCallCounter++;
138 d->mCallMap[ i ] = post;
140 d->readArgsFromPost( &args, *post );
141 d->mXmlRpcClient->call(
142 d->getCallFromFunction( Blogger1Private::ModifyPost ), args,
153 kError() <<
"Blogger1::createPost: post is null pointer";
157 unsigned int i= d->mCallCounter++;
158 d->mCallMap[ i ] = post;
159 kDebug() <<
"Creating new Post with blogid" <<
blogId();
161 d->readArgsFromPost( &args, *post );
162 d->mXmlRpcClient->call(
163 d->getCallFromFunction( Blogger1Private::CreatePost ), args,
174 kError() <<
"Blogger1::removePost: post is null pointer";
178 unsigned int i = d->mCallCounter++;
179 d->mCallMap[ i ] = post;
180 kDebug() <<
"Blogger1::removePost: postId=" << post->
postId();
183 d->mXmlRpcClient->call(
186 this, SLOT(slotError(
int,
QString,QVariant)),
190 Blogger1Private::Blogger1Private() :
197 Blogger1Private::~Blogger1Private()
200 delete mXmlRpcClient;
209 if ( !
id.isEmpty() ) {
224 if ( !
id.isEmpty() ) {
238 kDebug() <<
"TOP:" << result[0].typeName();
240 if ( result[0].type() != QVariant::Map ) {
241 kError() <<
"Could not fetch user's info out of the result from the server,"
244 i18n(
"Could not fetch user's info out of the result "
245 "from the server, not a map." ) );
256 emit q->fetchedUserInfo( userInfo );
265 kDebug() <<
"TOP:" << result[0].typeName();
267 if ( result[0].type() != QVariant::List ) {
268 kError() <<
"Could not fetch blogs out of the result from the server,"
271 i18n(
"Could not fetch blogs out of the result "
272 "from the server, not a list." ) );
278 for ( ; it != end; ++it ) {
279 kDebug() <<
"MIDDLE:" << ( *it ).typeName();
286 kDebug() <<
"Blog information retrieved: ID =" << blogInfo[
QLatin1String(
"id")]
288 blogsList << blogInfo;
290 emit q->listedBlogs( blogsList );
296 int count =
id.toInt();
300 kDebug() <<
"TOP:" << result[0].typeName();
304 if ( result[0].type() != QVariant::List ) {
305 kError() <<
"Could not fetch list of posts out of the"
306 <<
"result from the server, not a list.";
308 i18n(
"Could not fetch list of posts out of the result "
309 "from the server, not a list." ) );
315 for ( ; it != end; ++it ) {
317 kDebug() <<
"MIDDLE:" << ( *it ).typeName();
319 if ( readPostFromMap( &post, postInfo ) ) {
320 kDebug() <<
"Post with ID:"
322 <<
"appended in fetchedPostList";
324 fetchedPostList.
append( post );
326 kError() <<
"readPostFromMap failed!";
329 if ( --count == 0 ) {
333 kDebug() <<
"Emitting listRecentPostsFinished()";
334 emit q->listedRecentPosts( fetchedPostList );
343 mCallMap.remove(
id.toInt() );
348 kDebug () <<
"TOP:" << result[0].typeName();
349 if ( result[0].type() == QVariant::Map &&
350 readPostFromMap( post, result[0].toMap() ) ) {
351 kDebug() <<
"Emitting fetchedPost()";
353 emit q->fetchedPost( post );
355 kError() <<
"Could not fetch post out of the result from the server.";
356 post->
setError( i18n(
"Could not fetch post out of the result from the server." ) );
359 i18n(
"Could not fetch post out of the result from the server." ), post );
367 mCallMap.remove(
id.toInt() );
373 kDebug () <<
"TOP:" << result[0].typeName();
374 if ( result[0].type() != QVariant::String &&
375 result[0].type() != QVariant::Int ) {
376 kError() <<
"Could not read the postId, not a string or an integer.";
378 i18n(
"Could not read the postId, not a string or an integer." ),
383 if ( result[0].type() == QVariant::String ) {
384 serverID = result[0].toString();
385 }
else if ( result[0].type() == QVariant::Int ) {
390 kDebug() <<
"emitting createdPost()"
391 <<
"for title: \"" << post->
title()
392 <<
"\" server id: " << serverID;
393 emit q->createdPost( post );
400 mCallMap.remove(
id.toInt() );
406 kDebug() <<
"TOP:" << result[0].typeName();
407 if ( result[0].type() != QVariant::Bool &&
408 result[0].type() != QVariant::Int ) {
409 kError() <<
"Could not read the result, not a boolean.";
411 i18n(
"Could not read the result, not a boolean." ),
416 kDebug() <<
"emitting modifiedPost() for title: \""
417 << post->
title() <<
"\"";
418 emit q->modifiedPost( post );
425 mCallMap.remove(
id.toInt() );
427 kDebug() <<
"slotRemovePost";
431 kDebug() <<
"TOP:" << result[0].typeName();
432 if ( result[0].type() != QVariant::Bool &&
433 result[0].type() != QVariant::Int ) {
434 kError() <<
"Could not read the result, not a boolean.";
436 i18n(
"Could not read the result, not a boolean." ),
441 kDebug() <<
"emitting removedPost()";
442 emit q->removedPost( post );
445 void Blogger1Private::slotError(
int number,
451 kDebug() <<
"An error occurred: " << errorString;
452 BlogPost *post = mCallMap[
id.toInt() ];
460 bool Blogger1Private::readPostFromMap(
471 KDateTime dt( postInfo[
QLatin1String(
"dateCreated")].toDateTime(), KDateTime::UTC );
472 if ( dt.isValid() && !dt.isNull() ) {
475 dt = KDateTime ( postInfo[
QLatin1String(
"lastModified")].toDateTime(), KDateTime::UTC );
476 if ( dt.isValid() && !dt.isNull() ) {
485 if ( postInfo[
QLatin1String(
"content")].type() == QVariant::ByteArray ) {
496 if ( contents.
indexOf( titleMatch ) != -1 ) {
498 title = titleMatch.
cap( 1 );
500 if ( contents.
indexOf( categoryMatch ) != -1 ) {
504 contents.
remove( titleMatch );
505 contents.
remove( categoryMatch );
522 for ( it = categories.
constBegin(); it != end; ++it ) {
531 QString Blogger1Private::getCallFromFunction( FunctionToCall type )
534 case GetRecentPosts:
return QLatin1String(
"blogger.getRecentPosts");
542 #include "moc_blogger1.cpp"
QString title() const
Returns the title.
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
QString cap(int nth) const
virtual void setUrl(const KUrl &url)
Sets the URL for the blog's XML-RPC interface.
void modifyPost(KBlog::BlogPost *post)
Modify a post on server.
Status of a successfully fetched post.
virtual void fetchUserInfo()
Get information about the user from the blog.
Blogger1(const KUrl &server, QObject *parent=0)
Create an object for Blogger 1.0.
virtual ~Blogger1()
Destroy the object.
Status of a successfully created post.
void setUrl(const KUrl &server)
Set the Url of the server.
void listRecentPosts(int number)
List recent posts on the server.
This file is part of the for accessing Blog Servers and defines the Blogger1 class.
QString join(const QString &separator) const
QString & remove(int position, int n)
void setTitle(const QString &title)
Sets the title.
void setPostId(const QString &postId)
Sets the post id value.
QList< Key > keys() const
void setCreationDateTime(const KDateTime &datetime)
Sets the creation time.
void append(const T &value)
QString fromUtf8(const char *str, int size)
QStringList capturedTexts() const
void setContent(const QString &content)
Sets the content.
QString error() const
Returns the last error.
Status when an error on the server side occurred.
void setModificationDateTime(const KDateTime &datetime)
Sets the modification time.
QString blogId() const
Returns the unique ID for the specific blog on the server.
void setStatus(Status status)
Sets the status.
void removePost(KBlog::BlogPost *post)
Remove a post from the server.
Status of a successfully modified post.
QString content() const
Returns the content.
void fetchPost(KBlog::BlogPost *post)
Fetch a post from the server.
char * toString(const T &value)
A class that represents a blog post on the server.
A class that can be used for access to Blogger 1.0 blogs.
void setCategories(const QStringList &categories)
Sets the categories.
QString interfaceName() const
Returns the of the inherited object.
void createPost(KBlog::BlogPost *post)
Create a new post on server.
QString fromLatin1(const char *str, int size)
QStringList categories() const
Returns the categories.
const_iterator constEnd() const
const_iterator constBegin() const
A class that provides methods to call functions on a supported blog web application.
Status of a successfully removed post.
virtual void listBlogs()
List the blogs available for this authentication on the server.
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
bool isPrivate() const
Returns if the post is published or not.
QString postId() const
Returns the postId.
QString userAgent() const
Returns the HTTP user agent string used to make the HTTP requests.
An error in the XML-RPC client.
void setError(const QString &error)
Sets the error.