25 #include "blogcomment.h"
27 #include <syndication/loader.h>
28 #include <syndication/item.h>
29 #include <syndication/category.h>
31 #include <kio/netaccess.h>
34 #include <KLocalizedString>
39 #include <QDomDocument>
43 using namespace KBlog;
46 :
Blog( server, *new GDataPrivate, parent )
60 return QLatin1String(
"Google Blogger Data" );
66 return d_func()->mFullName;
79 return d_func()->mProfileId;
93 KIO::StoredTransferJob *job = KIO::storedGet(
url(), KIO::NoReload, KIO::HideProgressInfo );
95 connect( job, SIGNAL(result(KJob*)),
96 this, SLOT(slotFetchProfileId(KJob*)) );
102 Syndication::Loader *loader = Syndication::Loader::create();
104 SIGNAL(loadingComplete(Syndication::Loader*,Syndication::FeedPtr,Syndication::ErrorCode)),
106 SLOT(slotListBlogs(Syndication::Loader*,Syndication::FeedPtr,Syndication::ErrorCode)) );
107 loader->loadFrom( QString::fromLatin1(
"http://www.blogger.com/feeds/%1/blogs").arg(
profileId()) );
111 const KDateTime &upMinTime,
const KDateTime &upMaxTime,
112 const KDateTime &pubMinTime,
const KDateTime &pubMaxTime )
116 QString urlString( QLatin1String(
"http://www.blogger.com/feeds/") +
blogId() + QLatin1String(
"/posts/default") );
117 if ( ! labels.empty() ) {
118 urlString += QLatin1String(
"/-/") + labels.join( QLatin1String(
"/") );
120 kDebug() <<
"listRecentPosts()";
121 KUrl
url( urlString );
123 if ( !upMinTime.isNull() ) {
124 url.addQueryItem( QLatin1String(
"updated-min"), upMinTime.toString() );
127 if ( !upMaxTime.isNull() ) {
128 url.addQueryItem( QLatin1String(
"updated-max"), upMaxTime.toString() );
131 if ( !pubMinTime.isNull() ) {
132 url.addQueryItem( QLatin1String(
"published-min"), pubMinTime.toString() );
135 if ( !pubMaxTime.isNull() ) {
136 url.addQueryItem( QLatin1String(
"published-max"), pubMaxTime.toString() );
139 Syndication::Loader *loader = Syndication::Loader::create();
141 d->mListRecentPostsMap[ loader ] = number;
144 SIGNAL(loadingComplete(Syndication::Loader*,Syndication::FeedPtr,Syndication::ErrorCode)),
146 SLOT(slotListRecentPosts(Syndication::Loader*,Syndication::FeedPtr,Syndication::ErrorCode)) );
147 loader->loadFrom(
url.url() );
160 Syndication::Loader *loader = Syndication::Loader::create();
161 d->mListCommentsMap[ loader ] = post;
163 SIGNAL(loadingComplete(Syndication::Loader*,Syndication::FeedPtr,Syndication::ErrorCode)),
165 SLOT(slotListComments(Syndication::Loader*,Syndication::FeedPtr,Syndication::ErrorCode)) );
166 loader->loadFrom( QString(QLatin1String(
"http://www.blogger.com/feeds/") +
blogId() + QLatin1Char(
'/') +
167 post->
postId() + QLatin1String(
"/comments/default")) );
173 Syndication::Loader *loader = Syndication::Loader::create();
175 SIGNAL(loadingComplete(Syndication::Loader*,Syndication::FeedPtr,Syndication::ErrorCode)),
177 SLOT(slotListAllComments(Syndication::Loader*,Syndication::FeedPtr,Syndication::ErrorCode)) );
178 loader->loadFrom( QString::fromLatin1(
"http://www.blogger.com/feeds/%1/comments/default").arg(
blogId()) );
187 kError() <<
"post is null pointer";
192 Syndication::Loader *loader = Syndication::Loader::create();
193 d->mFetchPostMap[ loader ] = post;
195 SIGNAL(loadingComplete(Syndication::Loader*,Syndication::FeedPtr,Syndication::ErrorCode)),
197 SLOT(slotFetchPost(Syndication::Loader*,Syndication::FeedPtr,Syndication::ErrorCode)) );
198 loader->loadFrom( QString::fromLatin1(
"http://www.blogger.com/feeds/%1/posts/default").arg(
blogId()));
207 kError() <<
"post is null pointer";
211 if ( !d->authenticate() ) {
212 kError() <<
"Authentication failed.";
213 emit
errorPost(
Atom, i18n(
"Authentication failed." ), post );
217 QString atomMarkup = QLatin1String(
"<entry xmlns='http://www.w3.org/2005/Atom'>");
218 atomMarkup += QLatin1String(
"<id>tag:blogger.com,1999:blog-") +
blogId();
219 atomMarkup += QLatin1String(
".post-") + post->
postId() + QLatin1String(
"</id>");
220 atomMarkup += QLatin1String(
"<published>") + post->
creationDateTime().toString() + QLatin1String(
"</published>");
221 atomMarkup += QLatin1String(
"<updated>") + post->
modificationDateTime().toString() + QLatin1String(
"</updated>");
222 atomMarkup += QLatin1String(
"<title type='text'>") + post->
title() + QLatin1String(
"</title>");
224 atomMarkup += QLatin1String(
"<app:control xmlns:app='http://purl.org/atom/app#'>");
225 atomMarkup += QLatin1String(
"<app:draft>yes</app:draft></app:control>");
227 atomMarkup += QLatin1String(
"<content type='xhtml'>");
228 atomMarkup += QLatin1String(
"<div xmlns='http://www.w3.org/1999/xhtml'>");
230 atomMarkup += QLatin1String(
"</div></content>");
231 QList<QString>::ConstIterator it = post->
tags().constBegin();
232 QList<QString>::ConstIterator end = post->
tags().constEnd();
233 for ( ; it != end; ++it ) {
234 atomMarkup += QLatin1String(
"<category scheme='http://www.blogger.com/atom/ns#' term='") + ( *it ) + QLatin1String(
"' />");
236 atomMarkup += QLatin1String(
"<author>");
238 atomMarkup += QLatin1String(
"<name>") +
fullName() + QLatin1String(
"</name>");
240 atomMarkup += QLatin1String(
"<email>") +
username() + QLatin1String(
"</email>");
241 atomMarkup += QLatin1String(
"</author>");
242 atomMarkup += QLatin1String(
"</entry>");
244 QDataStream stream( &postData, QIODevice::WriteOnly );
245 stream.writeRawData( atomMarkup.toUtf8(), atomMarkup.toUtf8().length() );
247 KIO::StoredTransferJob *job = KIO::storedHttpPost( postData,
248 KUrl( QLatin1String(
"http://www.blogger.com/feeds/") +
blogId() + QLatin1String(
"/posts/default/") + post->
postId() ),
249 KIO::HideProgressInfo );
253 d->mModifyPostMap[ job ] = post;
255 job->addMetaData( QLatin1String(
"content-type"), QLatin1String(
"Content-Type: application/atom+xml; charset=utf-8") );
256 job->addMetaData( QLatin1String(
"ConnectTimeout"), QLatin1String(
"50") );
257 job->addMetaData( QLatin1String(
"UserAgent"),
userAgent() );
258 job->addMetaData( QLatin1String(
"customHTTPHeader"),
259 QLatin1String(
"Authorization: GoogleLogin auth=") + d->mAuthenticationString +
260 QLatin1String(
"\r\nX-HTTP-Method-Override: PUT") );
262 connect( job, SIGNAL(result(KJob*)),
263 this, SLOT(slotModifyPost(KJob*)) );
272 kError() <<
"post is null pointer";
276 if ( !d->authenticate() ) {
277 kError() <<
"Authentication failed.";
278 emit
errorPost(
Atom, i18n(
"Authentication failed." ), post );
282 QString atomMarkup = QLatin1String(
"<entry xmlns='http://www.w3.org/2005/Atom'>");
283 atomMarkup += QLatin1String(
"<title type='text'>") + post->
title() + QLatin1String(
"</title>");
285 atomMarkup += QLatin1String(
"<app:control xmlns:app='http://purl.org/atom/app#'>");
286 atomMarkup += QLatin1String(
"<app:draft>yes</app:draft></app:control>");
288 atomMarkup += QLatin1String(
"<content type='xhtml'>");
289 atomMarkup += QLatin1String(
"<div xmlns='http://www.w3.org/1999/xhtml'>");
291 atomMarkup += QLatin1String(
"</div></content>");
292 QList<QString>::ConstIterator it = post->
tags().constBegin();
293 QList<QString>::ConstIterator end = post->
tags().constEnd();
294 for ( ; it != end; ++it ) {
295 atomMarkup += QLatin1String(
"<category scheme='http://www.blogger.com/atom/ns#' term='") + ( *it ) + QLatin1String(
"' />");
297 atomMarkup += QLatin1String(
"<author>");
299 atomMarkup += QLatin1String(
"<name>") +
fullName() + QLatin1String(
"</name>");
301 atomMarkup += QLatin1String(
"<email>") +
username() + QLatin1String(
"</email>");
302 atomMarkup += QLatin1String(
"</author>");
303 atomMarkup += QLatin1String(
"</entry>");
306 QDataStream stream( &postData, QIODevice::WriteOnly );
307 stream.writeRawData( atomMarkup.toUtf8(), atomMarkup.toUtf8().length() );
309 KIO::StoredTransferJob *job = KIO::storedHttpPost( postData,
310 KUrl( QLatin1String(
"http://www.blogger.com/feeds/") +
blogId() + QLatin1String(
"/posts/default") ),
311 KIO::HideProgressInfo );
314 d->mCreatePostMap[ job ] = post;
316 job->addMetaData( QLatin1String(
"content-type"), QLatin1String(
"Content-Type: application/atom+xml; charset=utf-8") );
317 job->addMetaData( QLatin1String(
"ConnectTimeout"), QLatin1String(
"50") );
318 job->addMetaData( QLatin1String(
"UserAgent"),
userAgent() );
319 job->addMetaData( QLatin1String(
"customHTTPHeader"),
320 QLatin1String(
"Authorization: GoogleLogin auth=") + d->mAuthenticationString );
322 connect( job, SIGNAL(result(KJob*)),
323 this, SLOT(slotCreatePost(KJob*)) );
332 kError() <<
"post is null pointer";
336 if ( !d->authenticate() ) {
337 kError() <<
"Authentication failed.";
338 emit
errorPost(
Atom, i18n(
"Authentication failed." ), post );
344 KIO::StoredTransferJob *job = KIO::storedHttpPost( postData,
345 KUrl( QLatin1String(
"http://www.blogger.com/feeds/") +
blogId() + QLatin1String(
"/posts/default/") + post->
postId() ),
346 KIO::HideProgressInfo );
348 d->mRemovePostMap[ job ] = post;
351 kWarning() <<
"Unable to create KIO job for http://www.blogger.com/feeds/"
352 <<
blogId() << QLatin1String(
"/posts/default/") + post->
postId();
355 job->addMetaData( QLatin1String(
"ConnectTimeout"), QLatin1String(
"50") );
356 job->addMetaData( QLatin1String(
"UserAgent"),
userAgent() );
357 job->addMetaData( QLatin1String(
"customHTTPHeader"),
358 QLatin1String(
"Authorization: GoogleLogin auth=") + d->mAuthenticationString +
359 QLatin1String(
"\r\nX-HTTP-Method-Override: DELETE") );
361 connect( job, SIGNAL(result(KJob*)),
362 this, SLOT(slotRemovePost(KJob*)) );
370 kError() <<
"comment is null pointer";
375 kError() <<
"post is null pointer";
380 if ( !d->authenticate() ) {
381 kError() <<
"Authentication failed.";
385 QString atomMarkup = QLatin1String(
"<entry xmlns='http://www.w3.org/2005/Atom'>");
386 atomMarkup += QLatin1String(
"<title type=\"text\">") + comment->
title() + QLatin1String(
"</title>");
387 atomMarkup += QLatin1String(
"<content type=\"html\">") + comment->
content() + QLatin1String(
"</content>");
388 atomMarkup += QLatin1String(
"<author>");
389 atomMarkup += QLatin1String(
"<name>") + comment->
name() + QLatin1String(
"</name>");
390 atomMarkup += QLatin1String(
"<email>") + comment->
email() + QLatin1String(
"</email>");
391 atomMarkup += QLatin1String(
"</author></entry>");
394 kDebug() << postData;
395 QDataStream stream( &postData, QIODevice::WriteOnly );
396 stream.writeRawData( atomMarkup.toUtf8(), atomMarkup.toUtf8().length() );
398 KIO::StoredTransferJob *job = KIO::storedHttpPost( postData,
399 KUrl( QLatin1String(
"http://www.blogger.com/feeds/") +
blogId() + QLatin1String(
"/") + post->
postId() + QLatin1String(
"/comments/default") ),
400 KIO::HideProgressInfo );
402 d->mCreateCommentMap[ job ][post] = comment;
405 kWarning() <<
"Unable to create KIO job for http://www.blogger.com/feeds/"
406 <<
blogId() <<
"/" << post->
postId() <<
"/comments/default";
409 job->addMetaData( QLatin1String(
"content-type"), QLatin1String(
"Content-Type: application/atom+xml; charset=utf-8") );
410 job->addMetaData( QLatin1String(
"ConnectTimeout"), QLatin1String(
"50") );
411 job->addMetaData( QLatin1String(
"customHTTPHeader"),
412 QLatin1String(
"Authorization: GoogleLogin auth=") + d->mAuthenticationString );
413 job->addMetaData( QLatin1String(
"UserAgent"),
userAgent() );
415 connect( job, SIGNAL(result(KJob*)),
416 this, SLOT(slotCreateComment(KJob*)) );
426 kError() <<
"comment is null pointer";
431 kError() <<
"post is null pointer";
435 if ( !d->authenticate() ) {
436 kError() <<
"Authentication failed.";
443 KIO::StoredTransferJob *job = KIO::storedHttpPost(postData,
444 KUrl( QLatin1String(
"http://www.blogger.com/feeds/") +
blogId() + QLatin1String(
"/") + post->
postId() +
445 QLatin1String(
"/comments/default/") + comment->
commentId() ), KIO::HideProgressInfo );
446 d->mRemoveCommentMap[ job ][ post ] = comment;
449 kWarning() <<
"Unable to create KIO job for http://www.blogger.com/feeds/"
451 <<
"/comments/default/" << comment->
commentId();
454 job->addMetaData( QLatin1String(
"ConnectTimeout"), QLatin1String(
"50") );
455 job->addMetaData( QLatin1String(
"UserAgent"),
userAgent() );
456 job->addMetaData( QLatin1String(
"customHTTPHeader"),
457 QLatin1String(
"Authorization: GoogleLogin auth=") +
458 d->mAuthenticationString + QLatin1String(
"\r\nX-HTTP-Method-Override: DELETE") );
460 connect( job, SIGNAL(result(KJob*)),
461 this, SLOT(slotRemoveComment(KJob*)) );
464 GDataPrivate::GDataPrivate():mAuthenticationString(), mAuthenticationTime()
469 GDataPrivate::~GDataPrivate()
474 bool GDataPrivate::authenticate()
479 KUrl authGateway( QLatin1String(
"https://www.google.com/accounts/ClientLogin") );
480 authGateway.addQueryItem( QLatin1String(
"Email"), q->username() );
481 authGateway.addQueryItem( QLatin1String(
"Passwd"), q->password() );
482 authGateway.addQueryItem( QLatin1String(
"source"), q->userAgent() );
483 authGateway.addQueryItem( QLatin1String(
"service"), QLatin1String(
"blogger") );
484 if ( !mAuthenticationTime.isValid() ||
485 QDateTime::currentDateTime().toTime_t() - mAuthenticationTime.toTime_t() > TIMEOUT ||
486 mAuthenticationString.isEmpty() ) {
487 KIO::Job *job = KIO::http_post( authGateway, QByteArray(), KIO::HideProgressInfo );
488 if ( KIO::NetAccess::synchronousRun( job, (QWidget*)0, &data, &authGateway ) ) {
489 QRegExp rx( QLatin1String(
"Auth=(.+)") );
490 if ( rx.indexIn( QLatin1String(data) ) != -1 ) {
491 kDebug() <<
"RegExp got authentication string:" << rx.cap( 1 );
492 mAuthenticationString = rx.cap( 1 );
493 mAuthenticationTime = QDateTime::currentDateTime();
502 void GDataPrivate::slotFetchProfileId( KJob *job )
506 kError() <<
"job is a null pointer.";
510 KIO::StoredTransferJob *stj = qobject_cast<KIO::StoredTransferJob*>( job );
511 const QString data = QString::fromUtf8( stj->data(), stj->data().size() );
512 if ( !job->error() ) {
513 QRegExp pid( QLatin1String(
"http://www.blogger.com/profile/(\\d+)") );
514 if ( pid.indexIn( data ) != -1 ) {
515 q->setProfileId( pid.cap( 1 ) );
516 kDebug() <<
"QRegExp bid( 'http://www.blogger.com/profile/(\\d+)' matches" << pid.cap( 1 );
517 emit q->fetchedProfileId( pid.cap( 1 ) );
519 kError() <<
"QRegExp bid( 'http://www.blogger.com/profile/(\\d+)' "
520 <<
" could not regexp the Profile ID";
521 emit q->error(
GData::Other, i18n(
"Could not regexp the Profile ID." ) );
522 emit q->fetchedProfileId( QString() );
525 kError() <<
"Job Error: " << job->errorString();
527 emit q->fetchedProfileId( QString() );
531 void GDataPrivate::slotListBlogs( Syndication::Loader *loader,
532 Syndication::FeedPtr feed,
533 Syndication::ErrorCode status ) {
537 kError() <<
"loader is a null pointer.";
540 if ( status != Syndication::Success ) {
541 emit q->error(
GData::Atom, i18n(
"Could not get blogs." ) );
545 QList<QMap<QString,QString> > blogsList;
547 QList<Syndication::ItemPtr> items = feed->items();
548 QList<Syndication::ItemPtr>::ConstIterator it = items.constBegin();
549 QList<Syndication::ItemPtr>::ConstIterator end = items.constEnd();
550 for ( ; it != end; ++it ) {
551 QRegExp rx( QLatin1String(
"blog-(\\d+)") );
552 QMap<QString,QString> blogInfo;
553 if ( rx.indexIn( ( *it )->id() ) != -1 ) {
554 kDebug() <<
"QRegExp rx( 'blog-(\\d+)' matches" << rx.cap( 1 );
555 blogInfo[QLatin1String(
"id")] = rx.cap( 1 );
556 blogInfo[QLatin1String(
"title")] = ( *it )->title();
557 blogInfo[QLatin1String(
"url")] = ( *it )->link();
558 blogInfo[QLatin1String(
"summary")] = ( *it )->description();
559 blogsList << blogInfo;
561 kError() <<
"QRegExp rx( 'blog-(\\d+)' does not match anything in:"
563 emit q->error(
GData::Other, i18n(
"Could not regexp the blog id path." ) );
566 kDebug() <<
"Emitting listedBlogs(); ";
567 emit q->listedBlogs( blogsList );
570 void GDataPrivate::slotListComments( Syndication::Loader *loader,
571 Syndication::FeedPtr feed,
572 Syndication::ErrorCode status )
577 kError() <<
"loader is a null pointer.";
580 BlogPost *post = mListCommentsMap[ loader ];
581 mListCommentsMap.remove( loader );
583 if ( status != Syndication::Success ) {
584 emit q->errorPost(
GData::Atom, i18n(
"Could not get comments." ), post );
588 QList<KBlog::BlogComment> commentList;
590 QList<Syndication::ItemPtr> items = feed->items();
591 QList<Syndication::ItemPtr>::ConstIterator it = items.constBegin();
592 QList<Syndication::ItemPtr>::ConstIterator end = items.constEnd();
593 for ( ; it != end; ++it ) {
595 QRegExp rx( QLatin1String(
"post-(\\d+)") );
596 if ( rx.indexIn( ( *it )->id() ) == -1 ) {
597 kError() <<
"QRegExp rx( 'post-(\\d+)' does not match" << rx.cap( 1 );
598 emit q->error(
GData::Other, i18n(
"Could not regexp the comment id path." ) );
602 kDebug() <<
"QRegExp rx( 'post-(\\d+)' matches" << rx.cap( 1 );
603 comment.
setTitle( ( *it )->title() );
607 KDateTime( QDateTime::fromTime_t( ( *it )->datePublished() ),
608 KDateTime::Spec::UTC() ) );
610 KDateTime( QDateTime::fromTime_t( ( *it )->dateUpdated() ),
611 KDateTime::Spec::UTC() ) );
612 commentList.append( comment );
614 kDebug() <<
"Emitting listedComments()";
615 emit q->listedComments( post, commentList );
618 void GDataPrivate::slotListAllComments( Syndication::Loader *loader,
619 Syndication::FeedPtr feed,
620 Syndication::ErrorCode status )
625 kError() <<
"loader is a null pointer.";
629 if ( status != Syndication::Success ) {
630 emit q->error(
GData::Atom, i18n(
"Could not get comments." ) );
634 QList<KBlog::BlogComment> commentList;
636 QList<Syndication::ItemPtr> items = feed->items();
637 QList<Syndication::ItemPtr>::ConstIterator it = items.constBegin();
638 QList<Syndication::ItemPtr>::ConstIterator end = items.constEnd();
639 for ( ; it != end; ++it ) {
641 QRegExp rx( QLatin1String(
"post-(\\d+)") );
642 if ( rx.indexIn( ( *it )->id() ) == -1 ) {
643 kError() <<
"QRegExp rx( 'post-(\\d+)' does not match" << rx.cap( 1 );
644 emit q->error(
GData::Other, i18n(
"Could not regexp the comment id path." ) );
649 kDebug() <<
"QRegExp rx( 'post-(\\d+)' matches" << rx.cap( 1 );
650 comment.
setTitle( ( *it )->title() );
654 KDateTime( QDateTime::fromTime_t( ( *it )->datePublished() ),
655 KDateTime::Spec::UTC() ) );
657 KDateTime( QDateTime::fromTime_t( ( *it )->dateUpdated() ),
658 KDateTime::Spec::UTC() ) );
659 commentList.append( comment );
661 kDebug() <<
"Emitting listedAllComments()";
662 emit q->listedAllComments( commentList );
665 void GDataPrivate::slotListRecentPosts( Syndication::Loader *loader,
666 Syndication::FeedPtr feed,
667 Syndication::ErrorCode status ) {
671 kError() <<
"loader is a null pointer.";
675 if ( status != Syndication::Success ) {
676 emit q->error(
GData::Atom, i18n(
"Could not get posts." ) );
681 if ( mListRecentPostsMap.contains( loader ) ) {
682 number = mListRecentPostsMap[ loader ];
684 mListRecentPostsMap.remove( loader );
686 QList<KBlog::BlogPost> postList;
688 QList<Syndication::ItemPtr> items = feed->items();
689 QList<Syndication::ItemPtr>::ConstIterator it = items.constBegin();
690 QList<Syndication::ItemPtr>::ConstIterator end = items.constEnd();
691 for ( ; it != end; ++it ) {
693 QRegExp rx( QLatin1String(
"post-(\\d+)") );
694 if ( rx.indexIn( ( *it )->id() ) == -1 ) {
695 kError() <<
"QRegExp rx( 'post-(\\d+)' does not match" << rx.cap( 1 );
696 emit q->error(
GData::Other, i18n(
"Could not regexp the post id path." ) );
701 kDebug() <<
"QRegExp rx( 'post-(\\d+)' matches" << rx.cap( 1 );
704 post.
setLink( ( *it )->link() );
706 int catCount = ( *it )->categories().count();
707 QList< Syndication::CategoryPtr > cats = ( *it )->categories();
708 for (
int i=0; i < catCount; ++i ) {
709 if ( cats[i].get()->label().isEmpty() ) {
710 labels.append( cats[i].get()->term() );
712 labels.append( cats[i].get()->label() );
718 KDateTime( QDateTime::fromTime_t( ( *it )->datePublished() ),
719 KDateTime::Spec::UTC() ).toLocalZone() );
721 KDateTime( QDateTime::fromTime_t( ( *it )->dateUpdated() ),
722 KDateTime::Spec::UTC() ).toLocalZone() );
724 postList.append( post );
725 if ( number-- == 0 ) {
729 kDebug() <<
"Emitting listedRecentPosts()";
730 emit q->listedRecentPosts( postList );
733 void GDataPrivate::slotFetchPost( Syndication::Loader *loader,
734 Syndication::FeedPtr feed,
735 Syndication::ErrorCode status )
740 kError() <<
"loader is a null pointer.";
744 bool success =
false;
746 BlogPost *post = mFetchPostMap.take( loader );
747 kError() <<
"Post" << post;
750 if ( status != Syndication::Success ) {
751 emit q->errorPost(
GData::Atom, i18n(
"Could not get posts." ), post );
755 QString postId = post->
postId();
756 QList<Syndication::ItemPtr> items = feed->items();
757 QList<Syndication::ItemPtr>::ConstIterator it = items.constBegin();
758 QList<Syndication::ItemPtr>::ConstIterator end = items.constEnd();
759 for ( ; it != end; ++it ) {
760 QRegExp rx( QLatin1String(
"post-(\\d+)") );
761 if ( rx.indexIn( ( *it )->id() ) != -1 &&
762 rx.cap( 1 ) == postId ) {
763 kDebug() <<
"QRegExp rx( 'post-(\\d+)' matches" << rx.cap( 1 );
768 post->
setLink( ( *it )->link() );
770 KDateTime( QDateTime::fromTime_t( ( *it )->datePublished() ),
771 KDateTime::Spec::UTC() ).toLocalZone() );
773 KDateTime( QDateTime::fromTime_t( ( *it )->dateUpdated() ),
774 KDateTime::Spec::UTC() ).toLocalZone() );
775 kDebug() <<
"Emitting fetchedPost( postId=" << postId <<
");";
777 emit q->fetchedPost( post );
782 kError() <<
"QRegExp rx( 'post-(\\d+)' does not match"
783 << mFetchPostMap[ loader ]->postId() <<
".";
784 emit q->errorPost(
GData::Other, i18n(
"Could not regexp the blog id path." ), post );
788 void GDataPrivate::slotCreatePost( KJob *job )
792 kError() <<
"job is a null pointer.";
795 KIO::StoredTransferJob *stj = qobject_cast<KIO::StoredTransferJob*>( job );
796 const QString data = QString::fromUtf8( stj->data(), stj->data().size() );
801 mCreatePostMap.remove( job );
803 if ( job->error() != 0 ) {
804 kError() <<
"slotCreatePost error:" << job->errorString();
805 emit q->errorPost(
GData::Atom, job->errorString(), post );
809 QRegExp rxId( QLatin1String(
"post-(\\d+)") );
810 if ( rxId.indexIn( data ) == -1 ) {
811 kError() <<
"Could not regexp the id out of the result:" << data;
813 i18n(
"Could not regexp the id out of the result." ), post );
816 kDebug() <<
"QRegExp rx( 'post-(\\d+)' ) matches" << rxId.cap( 1 );
818 QRegExp rxPub( QLatin1String(
"<published>(.+)</published>") );
819 if ( rxPub.indexIn( data ) == -1 ) {
820 kError() <<
"Could not regexp the published time out of the result:" << data;
822 i18n(
"Could not regexp the published time out of the result." ), post );
825 kDebug() <<
"QRegExp rx( '<published>(.+)</published>' ) matches" << rxPub.cap( 1 );
827 QRegExp rxUp( QLatin1String(
"<updated>(.+)</updated>") );
828 if ( rxUp.indexIn( data ) == -1 ) {
829 kError() <<
"Could not regexp the update time out of the result:" << data;
831 i18n(
"Could not regexp the update time out of the result." ), post );
834 kDebug() <<
"QRegExp rx( '<updated>(.+)</updated>' ) matches" << rxUp.cap( 1 );
840 kDebug() <<
"Emitting createdPost()";
841 emit q->createdPost( post );
844 void GDataPrivate::slotModifyPost( KJob *job )
848 kError() <<
"job is a null pointer.";
851 KIO::StoredTransferJob *stj = qobject_cast<KIO::StoredTransferJob*>( job );
852 const QString data = QString::fromUtf8( stj->data(), stj->data().size() );
855 mModifyPostMap.remove( job );
857 if ( job->error() != 0 ) {
858 kError() <<
"slotModifyPost error:" << job->errorString();
859 emit q->errorPost(
GData::Atom, job->errorString(), post );
863 QRegExp rxId( QLatin1String(
"post-(\\d+)") );
864 if ( rxId.indexIn( data ) == -1 ) {
865 kError() <<
"Could not regexp the id out of the result:" << data;
867 i18n(
"Could not regexp the id out of the result." ), post );
870 kDebug() <<
"QRegExp rx( 'post-(\\d+)' ) matches" << rxId.cap( 1 );
872 QRegExp rxPub( QLatin1String(
"<published>(.+)</published>") );
873 if ( rxPub.indexIn( data ) == -1 ) {
874 kError() <<
"Could not regexp the published time out of the result:" << data;
876 i18n(
"Could not regexp the published time out of the result." ), post );
879 kDebug() <<
"QRegExp rx( '<published>(.+)</published>' ) matches" << rxPub.cap( 1 );
881 QRegExp rxUp( QLatin1String(
"<updated>(.+)</updated>") );
882 if ( rxUp.indexIn( data ) == -1 ) {
883 kError() <<
"Could not regexp the update time out of the result:" << data;
885 i18n(
"Could not regexp the update time out of the result." ), post );
888 kDebug() <<
"QRegExp rx( '<updated>(.+)</updated>' ) matches" << rxUp.cap( 1 );
893 emit q->modifiedPost( post );
896 void GDataPrivate::slotRemovePost( KJob *job )
900 kError() <<
"job is a null pointer.";
903 KIO::StoredTransferJob *stj = qobject_cast<KIO::StoredTransferJob*>( job );
904 const QString data = QString::fromUtf8( stj->data(), stj->data().size() );
907 mRemovePostMap.remove( job );
909 if ( job->error() != 0 ) {
910 kError() <<
"slotRemovePost error:" << job->errorString();
911 emit q->errorPost(
GData::Atom, job->errorString(), post );
916 kDebug() <<
"Emitting removedPost()";
917 emit q->removedPost( post );
920 void GDataPrivate::slotCreateComment( KJob *job )
924 kError() <<
"job is a null pointer.";
927 KIO::StoredTransferJob *stj = qobject_cast<KIO::StoredTransferJob*>( job );
928 const QString data = QString::fromUtf8( stj->data(), stj->data().size() );
929 kDebug() <<
"Dump data: " << data;
935 mCreateCommentMap.remove( job );
937 if ( job->error() != 0 ) {
938 kError() <<
"slotCreateComment error:" << job->errorString();
939 emit q->errorComment(
GData::Atom, job->errorString(), post, comment );
944 QRegExp rxId( QLatin1String(
"post-(\\d+)") );
945 if ( rxId.indexIn( data ) == -1 ) {
946 kError() <<
"Could not regexp the id out of the result:" << data;
948 i18n(
"Could not regexp the id out of the result." ), post );
951 kDebug() <<
"QRegExp rx( 'post-(\\d+)' ) matches" << rxId.cap( 1 );
953 QRegExp rxPub( QLatin1String(
"<published>(.+)</published>") );
954 if ( rxPub.indexIn( data ) == -1 ) {
955 kError() <<
"Could not regexp the published time out of the result:" << data;
957 i18n(
"Could not regexp the published time out of the result." ), post );
960 kDebug() <<
"QRegExp rx( '<published>(.+)</published>' ) matches" << rxPub.cap( 1 );
962 QRegExp rxUp( QLatin1String(
"<updated>(.+)</updated>") );
963 if ( rxUp.indexIn( data ) == -1 ) {
964 kError() <<
"Could not regexp the update time out of the result:" << data;
966 i18n(
"Could not regexp the update time out of the result." ), post );
969 kDebug() <<
"QRegExp rx( '<updated>(.+)</updated>' ) matches" << rxUp.cap( 1 );
974 kDebug() <<
"Emitting createdComment()";
975 emit q->createdComment( post, comment );
978 void GDataPrivate::slotRemoveComment( KJob *job )
982 kError() <<
"job is a null pointer.";
985 KIO::StoredTransferJob *stj = qobject_cast<KIO::StoredTransferJob*>( job );
986 const QString data = QString::fromUtf8( stj->data(), stj->data().size() );
992 mRemoveCommentMap.remove( job );
994 if ( job->error() != 0 ) {
995 kError() <<
"slotRemoveComment error:" << job->errorString();
996 emit q->errorComment(
GData::Atom, job->errorString(), post, comment );
1001 kDebug() <<
"Emitting removedComment()";
1002 emit q->removedComment( post, comment );
1005 #include "moc_gdata.cpp"