25 #include "blogcomment.h"
27 #include <syndication/loader.h>
28 #include <syndication/item.h>
29 #include <syndication/category.h>
31 #include <kio/netaccess.h>
35 #include <KLocalizedString>
40 #include <QDomDocument>
44 using namespace KBlog;
47 :
Blog( server, *new GDataPrivate, parent )
61 return QLatin1String(
"Google Blogger Data" );
67 return d_func()->mFullName;
80 return d_func()->mProfileId;
94 KIO::StoredTransferJob *job = KIO::storedGet(
url(), KIO::NoReload, KIO::HideProgressInfo );
96 connect( job, SIGNAL(result(KJob*)),
97 this, SLOT(slotFetchProfileId(KJob*)) );
103 Syndication::Loader *loader = Syndication::Loader::create();
105 SIGNAL(loadingComplete(Syndication::Loader*,Syndication::FeedPtr,Syndication::ErrorCode)),
107 SLOT(slotListBlogs(Syndication::Loader*,Syndication::FeedPtr,Syndication::ErrorCode)) );
108 loader->loadFrom( QString::fromLatin1(
"http://www.blogger.com/feeds/%1/blogs").arg(
profileId()) );
112 const KDateTime &upMinTime,
const KDateTime &upMaxTime,
113 const KDateTime &pubMinTime,
const KDateTime &pubMaxTime )
117 QString urlString( QLatin1String(
"http://www.blogger.com/feeds/") +
blogId() + QLatin1String(
"/posts/default") );
118 if ( ! labels.empty() ) {
119 urlString += QLatin1String(
"/-/") + labels.join( QLatin1String(
"/") );
121 kDebug() <<
"listRecentPosts()";
122 KUrl
url( urlString );
124 if ( !upMinTime.isNull() ) {
125 url.addQueryItem( QLatin1String(
"updated-min"), upMinTime.toString() );
128 if ( !upMaxTime.isNull() ) {
129 url.addQueryItem( QLatin1String(
"updated-max"), upMaxTime.toString() );
132 if ( !pubMinTime.isNull() ) {
133 url.addQueryItem( QLatin1String(
"published-min"), pubMinTime.toString() );
136 if ( !pubMaxTime.isNull() ) {
137 url.addQueryItem( QLatin1String(
"published-max"), pubMaxTime.toString() );
140 Syndication::Loader *loader = Syndication::Loader::create();
142 d->mListRecentPostsMap[ loader ] = number;
145 SIGNAL(loadingComplete(Syndication::Loader*,Syndication::FeedPtr,Syndication::ErrorCode)),
147 SLOT(slotListRecentPosts(Syndication::Loader*,Syndication::FeedPtr,Syndication::ErrorCode)) );
148 loader->loadFrom( url.url() );
161 Syndication::Loader *loader = Syndication::Loader::create();
162 d->mListCommentsMap[ loader ] = post;
164 SIGNAL(loadingComplete(Syndication::Loader*,Syndication::FeedPtr,Syndication::ErrorCode)),
166 SLOT(slotListComments(Syndication::Loader*,Syndication::FeedPtr,Syndication::ErrorCode)) );
167 loader->loadFrom( QString(QLatin1String(
"http://www.blogger.com/feeds/") +
blogId() + QLatin1Char(
'/') +
168 post->
postId() + QLatin1String(
"/comments/default")) );
174 Syndication::Loader *loader = Syndication::Loader::create();
176 SIGNAL(loadingComplete(Syndication::Loader*,Syndication::FeedPtr,Syndication::ErrorCode)),
178 SLOT(slotListAllComments(Syndication::Loader*,Syndication::FeedPtr,Syndication::ErrorCode)) );
179 loader->loadFrom( QString::fromLatin1(
"http://www.blogger.com/feeds/%1/comments/default").arg(
blogId()) );
188 kError() <<
"post is null pointer";
193 Syndication::Loader *loader = Syndication::Loader::create();
194 d->mFetchPostMap[ loader ] = post;
196 SIGNAL(loadingComplete(Syndication::Loader*,Syndication::FeedPtr,Syndication::ErrorCode)),
198 SLOT(slotFetchPost(Syndication::Loader*,Syndication::FeedPtr,Syndication::ErrorCode)) );
199 loader->loadFrom( QString::fromLatin1(
"http://www.blogger.com/feeds/%1/posts/default").arg(
blogId()));
208 kError() <<
"post is null pointer";
212 if ( !d->authenticate() ) {
213 kError() <<
"Authentication failed.";
214 emit
errorPost(
Atom, i18n(
"Authentication failed." ), post );
218 QString atomMarkup = QLatin1String(
"<entry xmlns='http://www.w3.org/2005/Atom'>");
219 atomMarkup += QLatin1String(
"<id>tag:blogger.com,1999:blog-") +
blogId();
220 atomMarkup += QLatin1String(
".post-") + post->
postId() + QLatin1String(
"</id>");
221 atomMarkup += QLatin1String(
"<published>") + post->
creationDateTime().toString() + QLatin1String(
"</published>");
222 atomMarkup += QLatin1String(
"<updated>") + post->
modificationDateTime().toString() + QLatin1String(
"</updated>");
223 atomMarkup += QLatin1String(
"<title type='text'>") + post->
title() + QLatin1String(
"</title>");
225 atomMarkup += QLatin1String(
"<app:control xmlns:app='http://purl.org/atom/app#'>");
226 atomMarkup += QLatin1String(
"<app:draft>yes</app:draft></app:control>");
228 atomMarkup += QLatin1String(
"<content type='xhtml'>");
229 atomMarkup += QLatin1String(
"<div xmlns='http://www.w3.org/1999/xhtml'>");
231 atomMarkup += QLatin1String(
"</div></content>");
232 QList<QString>::ConstIterator it = post->
tags().constBegin();
233 QList<QString>::ConstIterator end = post->
tags().constEnd();
234 for ( ; it != end; ++it ) {
235 atomMarkup += QLatin1String(
"<category scheme='http://www.blogger.com/atom/ns#' term='") + ( *it ) + QLatin1String(
"' />");
237 atomMarkup += QLatin1String(
"<author>");
239 atomMarkup += QLatin1String(
"<name>") +
fullName() + QLatin1String(
"</name>");
241 atomMarkup += QLatin1String(
"<email>") +
username() + QLatin1String(
"</email>");
242 atomMarkup += QLatin1String(
"</author>");
243 atomMarkup += QLatin1String(
"</entry>");
245 QDataStream stream( &postData, QIODevice::WriteOnly );
246 stream.writeRawData( atomMarkup.toUtf8(), atomMarkup.toUtf8().length() );
248 KIO::StoredTransferJob *job = KIO::storedHttpPost( postData,
249 KUrl( QLatin1String(
"http://www.blogger.com/feeds/") +
blogId() + QLatin1String(
"/posts/default/") + post->
postId() ),
250 KIO::HideProgressInfo );
254 d->mModifyPostMap[ job ] = post;
256 job->addMetaData( QLatin1String(
"content-type"), QLatin1String(
"Content-Type: application/atom+xml; charset=utf-8") );
257 job->addMetaData( QLatin1String(
"ConnectTimeout"), QLatin1String(
"50") );
258 job->addMetaData( QLatin1String(
"UserAgent"),
userAgent() );
259 job->addMetaData( QLatin1String(
"customHTTPHeader"),
260 QLatin1String(
"Authorization: GoogleLogin auth=") + d->mAuthenticationString +
261 QLatin1String(
"\r\nX-HTTP-Method-Override: PUT") );
263 connect( job, SIGNAL(result(KJob*)),
264 this, SLOT(slotModifyPost(KJob*)) );
273 kError() <<
"post is null pointer";
277 if ( !d->authenticate() ) {
278 kError() <<
"Authentication failed.";
279 emit
errorPost(
Atom, i18n(
"Authentication failed." ), post );
283 QString atomMarkup = QLatin1String(
"<entry xmlns='http://www.w3.org/2005/Atom'>");
284 atomMarkup += QLatin1String(
"<title type='text'>") + post->
title() + QLatin1String(
"</title>");
286 atomMarkup += QLatin1String(
"<app:control xmlns:app='http://purl.org/atom/app#'>");
287 atomMarkup += QLatin1String(
"<app:draft>yes</app:draft></app:control>");
289 atomMarkup += QLatin1String(
"<content type='xhtml'>");
290 atomMarkup += QLatin1String(
"<div xmlns='http://www.w3.org/1999/xhtml'>");
292 atomMarkup += QLatin1String(
"</div></content>");
293 QList<QString>::ConstIterator it = post->
tags().constBegin();
294 QList<QString>::ConstIterator end = post->
tags().constEnd();
295 for ( ; it != end; ++it ) {
296 atomMarkup += QLatin1String(
"<category scheme='http://www.blogger.com/atom/ns#' term='") + ( *it ) + QLatin1String(
"' />");
298 atomMarkup += QLatin1String(
"<author>");
300 atomMarkup += QLatin1String(
"<name>") +
fullName() + QLatin1String(
"</name>");
302 atomMarkup += QLatin1String(
"<email>") +
username() + QLatin1String(
"</email>");
303 atomMarkup += QLatin1String(
"</author>");
304 atomMarkup += QLatin1String(
"</entry>");
307 QDataStream stream( &postData, QIODevice::WriteOnly );
308 stream.writeRawData( atomMarkup.toUtf8(), atomMarkup.toUtf8().length() );
310 KIO::StoredTransferJob *job = KIO::storedHttpPost( postData,
311 KUrl( QLatin1String(
"http://www.blogger.com/feeds/") +
blogId() + QLatin1String(
"/posts/default") ),
312 KIO::HideProgressInfo );
315 d->mCreatePostMap[ job ] = post;
317 job->addMetaData( QLatin1String(
"content-type"), QLatin1String(
"Content-Type: application/atom+xml; charset=utf-8") );
318 job->addMetaData( QLatin1String(
"ConnectTimeout"), QLatin1String(
"50") );
319 job->addMetaData( QLatin1String(
"UserAgent"),
userAgent() );
320 job->addMetaData( QLatin1String(
"customHTTPHeader"),
321 QLatin1String(
"Authorization: GoogleLogin auth=") + d->mAuthenticationString );
323 connect( job, SIGNAL(result(KJob*)),
324 this, SLOT(slotCreatePost(KJob*)) );
333 kError() <<
"post is null pointer";
337 if ( !d->authenticate() ) {
338 kError() <<
"Authentication failed.";
339 emit
errorPost(
Atom, i18n(
"Authentication failed." ), post );
345 KIO::StoredTransferJob *job = KIO::storedHttpPost( postData,
346 KUrl( QLatin1String(
"http://www.blogger.com/feeds/") +
blogId() + QLatin1String(
"/posts/default/") + post->
postId() ),
347 KIO::HideProgressInfo );
349 d->mRemovePostMap[ job ] = post;
352 kWarning() <<
"Unable to create KIO job for http://www.blogger.com/feeds/"
353 <<
blogId() << QLatin1String(
"/posts/default/") + post->
postId();
356 job->addMetaData( QLatin1String(
"ConnectTimeout"), QLatin1String(
"50") );
357 job->addMetaData( QLatin1String(
"UserAgent"),
userAgent() );
358 job->addMetaData( QLatin1String(
"customHTTPHeader"),
359 QLatin1String(
"Authorization: GoogleLogin auth=") + d->mAuthenticationString +
360 QLatin1String(
"\r\nX-HTTP-Method-Override: DELETE") );
362 connect( job, SIGNAL(result(KJob*)),
363 this, SLOT(slotRemovePost(KJob*)) );
371 kError() <<
"comment is null pointer";
376 kError() <<
"post is null pointer";
381 if ( !d->authenticate() ) {
382 kError() <<
"Authentication failed.";
386 QString atomMarkup = QLatin1String(
"<entry xmlns='http://www.w3.org/2005/Atom'>");
387 atomMarkup += QLatin1String(
"<title type=\"text\">") + comment->
title() + QLatin1String(
"</title>");
388 atomMarkup += QLatin1String(
"<content type=\"html\">") + comment->
content() + QLatin1String(
"</content>");
389 atomMarkup += QLatin1String(
"<author>");
390 atomMarkup += QLatin1String(
"<name>") + comment->
name() + QLatin1String(
"</name>");
391 atomMarkup += QLatin1String(
"<email>") + comment->
email() + QLatin1String(
"</email>");
392 atomMarkup += QLatin1String(
"</author></entry>");
395 kDebug() << postData;
396 QDataStream stream( &postData, QIODevice::WriteOnly );
397 stream.writeRawData( atomMarkup.toUtf8(), atomMarkup.toUtf8().length() );
399 KIO::StoredTransferJob *job = KIO::storedHttpPost( postData,
400 KUrl( QLatin1String(
"http://www.blogger.com/feeds/") +
blogId() + QLatin1String(
"/") + post->
postId() + QLatin1String(
"/comments/default") ),
401 KIO::HideProgressInfo );
403 d->mCreateCommentMap[ job ][post] = comment;
406 kWarning() <<
"Unable to create KIO job for http://www.blogger.com/feeds/"
407 <<
blogId() <<
"/" << post->
postId() <<
"/comments/default";
410 job->addMetaData( QLatin1String(
"content-type"), QLatin1String(
"Content-Type: application/atom+xml; charset=utf-8") );
411 job->addMetaData( QLatin1String(
"ConnectTimeout"), QLatin1String(
"50") );
412 job->addMetaData( QLatin1String(
"customHTTPHeader"),
413 QLatin1String(
"Authorization: GoogleLogin auth=") + d->mAuthenticationString );
414 job->addMetaData( QLatin1String(
"UserAgent"),
userAgent() );
416 connect( job, SIGNAL(result(KJob*)),
417 this, SLOT(slotCreateComment(KJob*)) );
427 kError() <<
"comment is null pointer";
432 kError() <<
"post is null pointer";
436 if ( !d->authenticate() ) {
437 kError() <<
"Authentication failed.";
444 KIO::StoredTransferJob *job = KIO::storedHttpPost(postData,
445 KUrl( QLatin1String(
"http://www.blogger.com/feeds/") +
blogId() + QLatin1String(
"/") + post->
postId() +
446 QLatin1String(
"/comments/default/") + comment->
commentId() ), KIO::HideProgressInfo );
447 d->mRemoveCommentMap[ job ][ post ] = comment;
450 kWarning() <<
"Unable to create KIO job for http://www.blogger.com/feeds/"
452 <<
"/comments/default/" << comment->
commentId();
455 job->addMetaData( QLatin1String(
"ConnectTimeout"), QLatin1String(
"50") );
456 job->addMetaData( QLatin1String(
"UserAgent"),
userAgent() );
457 job->addMetaData( QLatin1String(
"customHTTPHeader"),
458 QLatin1String(
"Authorization: GoogleLogin auth=") +
459 d->mAuthenticationString + QLatin1String(
"\r\nX-HTTP-Method-Override: DELETE") );
461 connect( job, SIGNAL(result(KJob*)),
462 this, SLOT(slotRemoveComment(KJob*)) );
465 GDataPrivate::GDataPrivate():mAuthenticationString(), mAuthenticationTime()
470 GDataPrivate::~GDataPrivate()
475 bool GDataPrivate::authenticate()
480 KUrl authGateway( QLatin1String(
"https://www.google.com/accounts/ClientLogin") );
481 authGateway.addQueryItem( QLatin1String(
"Email"), q->username() );
482 authGateway.addQueryItem( QLatin1String(
"Passwd"), q->password() );
483 authGateway.addQueryItem( QLatin1String(
"source"), q->userAgent() );
484 authGateway.addQueryItem( QLatin1String(
"service"), QLatin1String(
"blogger") );
485 if ( !mAuthenticationTime.isValid() ||
486 QDateTime::currentDateTime().toTime_t() - mAuthenticationTime.toTime_t() > TIMEOUT ||
487 mAuthenticationString.isEmpty() ) {
488 KIO::Job *job = KIO::http_post( authGateway, QByteArray(), KIO::HideProgressInfo );
489 if ( KIO::NetAccess::synchronousRun( job, (QWidget*)0, &data, &authGateway ) ) {
490 QRegExp rx( QLatin1String(
"Auth=(.+)") );
491 if ( rx.indexIn( QLatin1String(data) ) != -1 ) {
492 kDebug() <<
"RegExp got authentication string:" << rx.cap( 1 );
493 mAuthenticationString = rx.cap( 1 );
494 mAuthenticationTime = QDateTime::currentDateTime();
503 void GDataPrivate::slotFetchProfileId( KJob *job )
507 kError() <<
"job is a null pointer.";
511 KIO::StoredTransferJob *stj = qobject_cast<KIO::StoredTransferJob*>( job );
512 const QString data = QString::fromUtf8( stj->data(), stj->data().size() );
513 if ( !job->error() ) {
514 QRegExp pid( QLatin1String(
"http://www.blogger.com/profile/(\\d+)") );
515 if ( pid.indexIn( data ) != -1 ) {
516 q->setProfileId( pid.cap( 1 ) );
517 kDebug() <<
"QRegExp bid( 'http://www.blogger.com/profile/(\\d+)' matches" << pid.cap( 1 );
518 emit q->fetchedProfileId( pid.cap( 1 ) );
520 kError() <<
"QRegExp bid( 'http://www.blogger.com/profile/(\\d+)' "
521 <<
" could not regexp the Profile ID";
522 emit q->error(
GData::Other, i18n(
"Could not regexp the Profile ID." ) );
523 emit q->fetchedProfileId( QString() );
526 kError() <<
"Job Error: " << job->errorString();
528 emit q->fetchedProfileId( QString() );
532 void GDataPrivate::slotListBlogs( Syndication::Loader *loader,
533 Syndication::FeedPtr feed,
534 Syndication::ErrorCode status ) {
538 kError() <<
"loader is a null pointer.";
541 if ( status != Syndication::Success ) {
542 emit q->error(
GData::Atom, i18n(
"Could not get blogs." ) );
546 QList<QMap<QString,QString> > blogsList;
548 QList<Syndication::ItemPtr> items = feed->items();
549 QList<Syndication::ItemPtr>::ConstIterator it = items.constBegin();
550 QList<Syndication::ItemPtr>::ConstIterator end = items.constEnd();
551 for ( ; it != end; ++it ) {
552 QRegExp rx( QLatin1String(
"blog-(\\d+)") );
553 QMap<QString,QString> blogInfo;
554 if ( rx.indexIn( ( *it )->id() ) != -1 ) {
555 kDebug() <<
"QRegExp rx( 'blog-(\\d+)' matches" << rx.cap( 1 );
556 blogInfo[QLatin1String(
"id")] = rx.cap( 1 );
557 blogInfo[QLatin1String(
"title")] = ( *it )->title();
558 blogInfo[QLatin1String(
"url")] = ( *it )->link();
559 blogInfo[QLatin1String(
"summary")] = ( *it )->description();
560 blogsList << blogInfo;
562 kError() <<
"QRegExp rx( 'blog-(\\d+)' does not match anything in:"
564 emit q->error(
GData::Other, i18n(
"Could not regexp the blog id path." ) );
567 kDebug() <<
"Emitting listedBlogs(); ";
568 emit q->listedBlogs( blogsList );
571 void GDataPrivate::slotListComments( Syndication::Loader *loader,
572 Syndication::FeedPtr feed,
573 Syndication::ErrorCode status )
578 kError() <<
"loader is a null pointer.";
581 BlogPost *post = mListCommentsMap[ loader ];
582 mListCommentsMap.remove( loader );
584 if ( status != Syndication::Success ) {
585 emit q->errorPost(
GData::Atom, i18n(
"Could not get comments." ), post );
589 QList<KBlog::BlogComment> commentList;
591 QList<Syndication::ItemPtr> items = feed->items();
592 QList<Syndication::ItemPtr>::ConstIterator it = items.constBegin();
593 QList<Syndication::ItemPtr>::ConstIterator end = items.constEnd();
594 for ( ; it != end; ++it ) {
596 QRegExp rx( QLatin1String(
"post-(\\d+)") );
597 if ( rx.indexIn( ( *it )->id() ) == -1 ) {
598 kError() <<
"QRegExp rx( 'post-(\\d+)' does not match" << rx.cap( 1 );
599 emit q->error(
GData::Other, i18n(
"Could not regexp the comment id path." ) );
603 kDebug() <<
"QRegExp rx( 'post-(\\d+)' matches" << rx.cap( 1 );
604 comment.
setTitle( ( *it )->title() );
608 KDateTime( QDateTime::fromTime_t( ( *it )->datePublished() ),
609 KDateTime::Spec::UTC() ) );
611 KDateTime( QDateTime::fromTime_t( ( *it )->dateUpdated() ),
612 KDateTime::Spec::UTC() ) );
613 commentList.append( comment );
615 kDebug() <<
"Emitting listedComments()";
616 emit q->listedComments( post, commentList );
619 void GDataPrivate::slotListAllComments( Syndication::Loader *loader,
620 Syndication::FeedPtr feed,
621 Syndication::ErrorCode status )
626 kError() <<
"loader is a null pointer.";
630 if ( status != Syndication::Success ) {
631 emit q->error(
GData::Atom, i18n(
"Could not get comments." ) );
635 QList<KBlog::BlogComment> commentList;
637 QList<Syndication::ItemPtr> items = feed->items();
638 QList<Syndication::ItemPtr>::ConstIterator it = items.constBegin();
639 QList<Syndication::ItemPtr>::ConstIterator end = items.constEnd();
640 for ( ; it != end; ++it ) {
642 QRegExp rx( QLatin1String(
"post-(\\d+)") );
643 if ( rx.indexIn( ( *it )->id() ) == -1 ) {
644 kError() <<
"QRegExp rx( 'post-(\\d+)' does not match" << rx.cap( 1 );
645 emit q->error(
GData::Other, i18n(
"Could not regexp the comment id path." ) );
650 kDebug() <<
"QRegExp rx( 'post-(\\d+)' matches" << rx.cap( 1 );
651 comment.
setTitle( ( *it )->title() );
655 KDateTime( QDateTime::fromTime_t( ( *it )->datePublished() ),
656 KDateTime::Spec::UTC() ) );
658 KDateTime( QDateTime::fromTime_t( ( *it )->dateUpdated() ),
659 KDateTime::Spec::UTC() ) );
660 commentList.append( comment );
662 kDebug() <<
"Emitting listedAllComments()";
663 emit q->listedAllComments( commentList );
666 void GDataPrivate::slotListRecentPosts( Syndication::Loader *loader,
667 Syndication::FeedPtr feed,
668 Syndication::ErrorCode status ) {
672 kError() <<
"loader is a null pointer.";
676 if ( status != Syndication::Success ) {
677 emit q->error(
GData::Atom, i18n(
"Could not get posts." ) );
682 if ( mListRecentPostsMap.contains( loader ) ) {
683 number = mListRecentPostsMap[ loader ];
685 mListRecentPostsMap.remove( loader );
687 QList<KBlog::BlogPost> postList;
689 QList<Syndication::ItemPtr> items = feed->items();
690 QList<Syndication::ItemPtr>::ConstIterator it = items.constBegin();
691 QList<Syndication::ItemPtr>::ConstIterator end = items.constEnd();
692 for ( ; it != end; ++it ) {
694 QRegExp rx( QLatin1String(
"post-(\\d+)") );
695 if ( rx.indexIn( ( *it )->id() ) == -1 ) {
696 kError() <<
"QRegExp rx( 'post-(\\d+)' does not match" << rx.cap( 1 );
697 emit q->error(
GData::Other, i18n(
"Could not regexp the post id path." ) );
702 kDebug() <<
"QRegExp rx( 'post-(\\d+)' matches" << rx.cap( 1 );
705 post.
setLink( ( *it )->link() );
707 int catCount = ( *it )->categories().count();
708 QList< Syndication::CategoryPtr > cats = ( *it )->categories();
709 for (
int i=0; i < catCount; ++i ) {
710 if ( cats[i].
get()->label().isEmpty() ) {
711 labels.append( cats[i].
get()->term() );
713 labels.append( cats[i].
get()->label() );
719 KDateTime( QDateTime::fromTime_t( ( *it )->datePublished() ),
720 KDateTime::Spec::UTC() ).toLocalZone() );
722 KDateTime( QDateTime::fromTime_t( ( *it )->dateUpdated() ),
723 KDateTime::Spec::UTC() ).toLocalZone() );
725 postList.append( post );
726 if ( number-- == 0 ) {
730 kDebug() <<
"Emitting listedRecentPosts()";
731 emit q->listedRecentPosts( postList );
734 void GDataPrivate::slotFetchPost( Syndication::Loader *loader,
735 Syndication::FeedPtr feed,
736 Syndication::ErrorCode status )
741 kError() <<
"loader is a null pointer.";
745 bool success =
false;
747 BlogPost *post = mFetchPostMap.take( loader );
748 kError() <<
"Post" << post;
751 if ( status != Syndication::Success ) {
752 emit q->errorPost(
GData::Atom, i18n(
"Could not get posts." ), post );
756 QString postId = post->
postId();
757 QList<Syndication::ItemPtr> items = feed->items();
758 QList<Syndication::ItemPtr>::ConstIterator it = items.constBegin();
759 QList<Syndication::ItemPtr>::ConstIterator end = items.constEnd();
760 for ( ; it != end; ++it ) {
761 QRegExp rx( QLatin1String(
"post-(\\d+)") );
762 if ( rx.indexIn( ( *it )->id() ) != -1 &&
763 rx.cap( 1 ) == postId ) {
764 kDebug() <<
"QRegExp rx( 'post-(\\d+)' matches" << rx.cap( 1 );
769 post->
setLink( ( *it )->link() );
771 KDateTime( QDateTime::fromTime_t( ( *it )->datePublished() ),
772 KDateTime::Spec::UTC() ).toLocalZone() );
774 KDateTime( QDateTime::fromTime_t( ( *it )->dateUpdated() ),
775 KDateTime::Spec::UTC() ).toLocalZone() );
776 kDebug() <<
"Emitting fetchedPost( postId=" << postId <<
");";
778 emit q->fetchedPost( post );
783 kError() <<
"QRegExp rx( 'post-(\\d+)' does not match"
784 << mFetchPostMap[ loader ]->postId() <<
".";
785 emit q->errorPost(
GData::Other, i18n(
"Could not regexp the blog id path." ), post );
789 void GDataPrivate::slotCreatePost( KJob *job )
793 kError() <<
"job is a null pointer.";
796 KIO::StoredTransferJob *stj = qobject_cast<KIO::StoredTransferJob*>( job );
797 const QString data = QString::fromUtf8( stj->data(), stj->data().size() );
802 mCreatePostMap.remove( job );
804 if ( job->error() != 0 ) {
805 kError() <<
"slotCreatePost error:" << job->errorString();
806 emit q->errorPost(
GData::Atom, job->errorString(), post );
810 QRegExp rxId( QLatin1String(
"post-(\\d+)") );
811 if ( rxId.indexIn( data ) == -1 ) {
812 kError() <<
"Could not regexp the id out of the result:" << data;
814 i18n(
"Could not regexp the id out of the result." ), post );
817 kDebug() <<
"QRegExp rx( 'post-(\\d+)' ) matches" << rxId.cap( 1 );
819 QRegExp rxPub( QLatin1String(
"<published>(.+)</published>") );
820 if ( rxPub.indexIn( data ) == -1 ) {
821 kError() <<
"Could not regexp the published time out of the result:" << data;
823 i18n(
"Could not regexp the published time out of the result." ), post );
826 kDebug() <<
"QRegExp rx( '<published>(.+)</published>' ) matches" << rxPub.cap( 1 );
828 QRegExp rxUp( QLatin1String(
"<updated>(.+)</updated>") );
829 if ( rxUp.indexIn( data ) == -1 ) {
830 kError() <<
"Could not regexp the update time out of the result:" << data;
832 i18n(
"Could not regexp the update time out of the result." ), post );
835 kDebug() <<
"QRegExp rx( '<updated>(.+)</updated>' ) matches" << rxUp.cap( 1 );
841 kDebug() <<
"Emitting createdPost()";
842 emit q->createdPost( post );
845 void GDataPrivate::slotModifyPost( KJob *job )
849 kError() <<
"job is a null pointer.";
852 KIO::StoredTransferJob *stj = qobject_cast<KIO::StoredTransferJob*>( job );
853 const QString data = QString::fromUtf8( stj->data(), stj->data().size() );
856 mModifyPostMap.remove( job );
858 if ( job->error() != 0 ) {
859 kError() <<
"slotModifyPost error:" << job->errorString();
860 emit q->errorPost(
GData::Atom, job->errorString(), post );
864 QRegExp rxId( QLatin1String(
"post-(\\d+)") );
865 if ( rxId.indexIn( data ) == -1 ) {
866 kError() <<
"Could not regexp the id out of the result:" << data;
868 i18n(
"Could not regexp the id out of the result." ), post );
871 kDebug() <<
"QRegExp rx( 'post-(\\d+)' ) matches" << rxId.cap( 1 );
873 QRegExp rxPub( QLatin1String(
"<published>(.+)</published>") );
874 if ( rxPub.indexIn( data ) == -1 ) {
875 kError() <<
"Could not regexp the published time out of the result:" << data;
877 i18n(
"Could not regexp the published time out of the result." ), post );
880 kDebug() <<
"QRegExp rx( '<published>(.+)</published>' ) matches" << rxPub.cap( 1 );
882 QRegExp rxUp( QLatin1String(
"<updated>(.+)</updated>") );
883 if ( rxUp.indexIn( data ) == -1 ) {
884 kError() <<
"Could not regexp the update time out of the result:" << data;
886 i18n(
"Could not regexp the update time out of the result." ), post );
889 kDebug() <<
"QRegExp rx( '<updated>(.+)</updated>' ) matches" << rxUp.cap( 1 );
890 post->setPostId( rxId.cap( 1 ) );
891 post->setCreationDateTime( KDateTime().fromString( rxPub.cap( 1 ) ) );
892 post->setModificationDateTime( KDateTime().fromString( rxUp.cap( 1 ) ) );
894 emit q->modifiedPost( post );
897 void GDataPrivate::slotRemovePost( KJob *job )
901 kError() <<
"job is a null pointer.";
904 KIO::StoredTransferJob *stj = qobject_cast<KIO::StoredTransferJob*>( job );
905 const QString data = QString::fromUtf8( stj->data(), stj->data().size() );
908 mRemovePostMap.remove( job );
910 if ( job->error() != 0 ) {
911 kError() <<
"slotRemovePost error:" << job->errorString();
912 emit q->errorPost(
GData::Atom, job->errorString(), post );
917 kDebug() <<
"Emitting removedPost()";
918 emit q->removedPost( post );
921 void GDataPrivate::slotCreateComment( KJob *job )
925 kError() <<
"job is a null pointer.";
928 KIO::StoredTransferJob *stj = qobject_cast<KIO::StoredTransferJob*>( job );
929 const QString data = QString::fromUtf8( stj->data(), stj->data().size() );
930 kDebug() <<
"Dump data: " << data;
936 mCreateCommentMap.remove( job );
938 if ( job->error() != 0 ) {
939 kError() <<
"slotCreateComment error:" << job->errorString();
940 emit q->errorComment(
GData::Atom, job->errorString(), post, comment );
945 QRegExp rxId( QLatin1String(
"post-(\\d+)") );
946 if ( rxId.indexIn( data ) == -1 ) {
947 kError() <<
"Could not regexp the id out of the result:" << data;
949 i18n(
"Could not regexp the id out of the result." ), post );
952 kDebug() <<
"QRegExp rx( 'post-(\\d+)' ) matches" << rxId.cap( 1 );
954 QRegExp rxPub( QLatin1String(
"<published>(.+)</published>") );
955 if ( rxPub.indexIn( data ) == -1 ) {
956 kError() <<
"Could not regexp the published time out of the result:" << data;
958 i18n(
"Could not regexp the published time out of the result." ), post );
961 kDebug() <<
"QRegExp rx( '<published>(.+)</published>' ) matches" << rxPub.cap( 1 );
963 QRegExp rxUp( QLatin1String(
"<updated>(.+)</updated>") );
964 if ( rxUp.indexIn( data ) == -1 ) {
965 kError() <<
"Could not regexp the update time out of the result:" << data;
967 i18n(
"Could not regexp the update time out of the result." ), post );
970 kDebug() <<
"QRegExp rx( '<updated>(.+)</updated>' ) matches" << rxUp.cap( 1 );
975 kDebug() <<
"Emitting createdComment()";
976 emit q->createdComment( post, comment );
979 void GDataPrivate::slotRemoveComment( KJob *job )
983 kError() <<
"job is a null pointer.";
986 KIO::StoredTransferJob *stj = qobject_cast<KIO::StoredTransferJob*>( job );
987 const QString data = QString::fromUtf8( stj->data(), stj->data().size() );
993 mRemoveCommentMap.remove( job );
995 if ( job->error() != 0 ) {
996 kError() <<
"slotRemoveComment error:" << job->errorString();
997 emit q->errorComment(
GData::Atom, job->errorString(), post, comment );
1002 kDebug() <<
"Emitting removedComment()";
1003 emit q->removedComment( post, comment );
1006 #include "moc_gdata.cpp"
QString title() const
Returns the title.
virtual void setUrl(const KUrl &url)
Sets the URL for the blog's XML-RPC interface.
KDateTime creationDateTime() const
Returns the creation date time.
void modifyPost(KBlog::BlogPost *post)
Modify a post on server.
Status of a successfully fetched post.
void setLink(const KUrl &link) const
Set the link path.
void removePost(KBlog::BlogPost *post)
Remove a post from the server.
virtual void listBlogs()
List the blogs available for this authentication on the server.
QStringList tags() const
Returns the tags list as a QStringList.
QString profileId() const
Returns the profile id of the blog.
Status of a successfully created post.
A class that can be used for access to GData blogs.
GData(const KUrl &server, QObject *parent=0)
Create an object for GData.
void setTitle(const QString &title)
Sets the title.
virtual void removeComment(KBlog::BlogPost *post, KBlog::BlogComment *comment)
Remove a comment from the server.
void setPostId(const QString &postId)
Sets the post id value.
QString username() const
Returns the username used in blog authentication.
virtual void listAllComments()
List the all comments available for this authentication on the server.
void setCreationDateTime(const KDateTime &datetime)
Sets the creation time.
virtual void setProfileId(const QString &pid)
Get the profile's id of the blog.
This file is part of the for accessing Blog Servers and defines the GData class.
virtual void createComment(KBlog::BlogPost *post, KBlog::BlogComment *comment)
Create a comment on the server.
void errorPost(KBlog::Blog::ErrorType type, const QString &errorMessage, KBlog::BlogPost *post)
This signal is emitted when an error occurs with XML parsing or a structural problem in an operation ...
virtual void setFullName(const QString &fullName)
Sets the user's name for the blog.
void setContent(const QString &content)
Sets the content.
KDateTime modificationDateTime() const
Returns the modification date time.
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.
Status of a successfully modified post.
KUrl url() const
Get the URL for the blog's XML-RPC interface.
void listRecentPosts(int number)
List recent posts on the server.
void fetchPost(KBlog::BlogPost *post)
Fetch the Post with a specific id.
QString fullName() const
Returns the full name of user of the blog.
QString content() const
Returns the content.
virtual void listComments(KBlog::BlogPost *post)
List the comments available for this post on the server.
An error in the syndication client.
A class that represents a blog post on the server.
QString interfaceName() const
Returns the of the inherited object.
void fetchProfileId()
Get information about the profile from the blog.
void setTags(const QStringList &tags)
Set the tags list.
A class that provides methods to call functions on a supported blog web application.
Status of a successfully removed post.
void createPost(KBlog::BlogPost *post)
Create a new post on server.
void errorComment(KBlog::Blog::ErrorType type, const QString &errorMessage, KBlog::BlogPost *post, KBlog::BlogComment *comment)
This signal is emitted when an error occurs with XML parsing or a structural problem in an operation ...
bool isPrivate() const
Returns if the post is published or not.
Any other miscellaneous error.
QString postId() const
Returns the postId.
QString userAgent() const
Returns the HTTP user agent string used to make the HTTP requests.