25 #include "blogcomment.h"
27 #include <syndication/loader.h>
28 #include <syndication/item.h>
29 #include <syndication/category.h>
31 #include <kio/netaccess.h>
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(
"http://www.blogger.com/feeds/" +
blogId() +
"/posts/default" );
118 if ( ! labels.empty() ) {
119 urlString +=
"/-/" + labels.join(
"/" );
121 kDebug() <<
"listRecentPosts()";
122 KUrl
url( urlString );
124 if ( !upMinTime.isNull() ) {
125 url.addQueryItem(
"updated-min", upMinTime.toString() );
128 if ( !upMaxTime.isNull() ) {
129 url.addQueryItem(
"updated-max", upMaxTime.toString() );
132 if ( !pubMinTime.isNull() ) {
133 url.addQueryItem(
"published-min", pubMinTime.toString() );
136 if ( !pubMaxTime.isNull() ) {
137 url.addQueryItem(
"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(
"http://www.blogger.com/feeds/" +
blogId() +
'/' +
168 post->
postId() +
"/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 =
"<entry xmlns='http://www.w3.org/2005/Atom'>";
219 atomMarkup +=
"<id>tag:blogger.com,1999:blog-" +
blogId();
220 atomMarkup +=
".post-" + post->
postId() +
"</id>";
221 atomMarkup +=
"<published>" + post->
creationDateTime().toString() +
"</published>";
223 atomMarkup +=
"<title type='text'>" + post->
title() +
"</title>";
225 atomMarkup +=
"<app:control xmlns:app='http://purl.org/atom/app#'>";
226 atomMarkup +=
"<app:draft>yes</app:draft></app:control>";
228 atomMarkup +=
"<content type='xhtml'>";
229 atomMarkup +=
"<div xmlns='http://www.w3.org/1999/xhtml'>";
231 atomMarkup +=
"</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 +=
"<category scheme='http://www.blogger.com/atom/ns#' term='" + ( *it ) +
"' />";
237 atomMarkup +=
"<author>";
239 atomMarkup +=
"<name>" +
fullName() +
"</name>";
241 atomMarkup +=
"<email>" +
username() +
"</email>";
242 atomMarkup +=
"</author>";
243 atomMarkup +=
"</entry>";
245 QDataStream stream( &postData, QIODevice::WriteOnly );
246 stream.writeRawData( atomMarkup.toUtf8(), atomMarkup.toUtf8().length() );
248 KIO::StoredTransferJob *job = KIO::storedHttpPost( postData,
249 KUrl(
"http://www.blogger.com/feeds/" +
blogId() +
"/posts/default/" + post->
postId() ),
250 KIO::HideProgressInfo );
254 d->mModifyPostMap[ job ] = post;
256 job->addMetaData(
"content-type",
"Content-Type: application/atom+xml; charset=utf-8" );
257 job->addMetaData(
"ConnectTimeout",
"50" );
258 job->addMetaData(
"UserAgent",
userAgent() );
259 job->addMetaData(
"customHTTPHeader",
260 "Authorization: GoogleLogin auth=" + d->mAuthenticationString +
261 "\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 =
"<entry xmlns='http://www.w3.org/2005/Atom'>";
284 atomMarkup +=
"<title type='text'>" + post->
title() +
"</title>";
286 atomMarkup +=
"<app:control xmlns:app='http://purl.org/atom/app#'>";
287 atomMarkup +=
"<app:draft>yes</app:draft></app:control>";
289 atomMarkup +=
"<content type='xhtml'>";
290 atomMarkup +=
"<div xmlns='http://www.w3.org/1999/xhtml'>";
292 atomMarkup +=
"</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 +=
"<category scheme='http://www.blogger.com/atom/ns#' term='" + ( *it ) +
"' />";
298 atomMarkup +=
"<author>";
300 atomMarkup +=
"<name>" +
fullName() +
"</name>";
302 atomMarkup +=
"<email>" +
username() +
"</email>";
303 atomMarkup +=
"</author>";
304 atomMarkup +=
"</entry>";
307 QDataStream stream( &postData, QIODevice::WriteOnly );
308 stream.writeRawData( atomMarkup.toUtf8(), atomMarkup.toUtf8().length() );
310 KIO::StoredTransferJob *job = KIO::storedHttpPost( postData,
311 KUrl(
"http://www.blogger.com/feeds/" +
blogId() +
"/posts/default" ),
312 KIO::HideProgressInfo );
315 d->mCreatePostMap[ job ] = post;
317 job->addMetaData(
"content-type",
"Content-Type: application/atom+xml; charset=utf-8" );
318 job->addMetaData(
"ConnectTimeout",
"50" );
319 job->addMetaData(
"UserAgent",
userAgent() );
320 job->addMetaData(
"customHTTPHeader",
321 "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(
"http://www.blogger.com/feeds/" +
blogId() +
"/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/"
356 job->addMetaData(
"ConnectTimeout",
"50" );
357 job->addMetaData(
"UserAgent",
userAgent() );
358 job->addMetaData(
"customHTTPHeader",
359 "Authorization: GoogleLogin auth=" + d->mAuthenticationString +
360 "\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 =
"<entry xmlns='http://www.w3.org/2005/Atom'>";
387 atomMarkup +=
"<title type=\"text\">" + comment->
title() +
"</title>";
388 atomMarkup +=
"<content type=\"html\">" + comment->
content() +
"</content>";
389 atomMarkup +=
"<author>";
390 atomMarkup +=
"<name>" + comment->
name() +
"</name>";
391 atomMarkup +=
"<email>" + comment->
email() +
"</email>";
392 atomMarkup +=
"</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(
"http://www.blogger.com/feeds/" +
blogId() +
"/" + post->
postId() +
"/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(
"content-type",
"Content-Type: application/atom+xml; charset=utf-8" );
411 job->addMetaData(
"ConnectTimeout",
"50" );
412 job->addMetaData(
"customHTTPHeader",
413 "Authorization: GoogleLogin auth=" + d->mAuthenticationString );
414 job->addMetaData(
"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(
"http://www.blogger.com/feeds/" +
blogId() +
"/" + post->
postId() +
446 "/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(
"ConnectTimeout",
"50" );
456 job->addMetaData(
"UserAgent",
userAgent() );
457 job->addMetaData(
"customHTTPHeader",
458 "Authorization: GoogleLogin auth=" +
459 d->mAuthenticationString +
"\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(
"https://www.google.com/accounts/ClientLogin" );
481 authGateway.addQueryItem(
"Email", q->username() );
482 authGateway.addQueryItem(
"Passwd", q->password() );
483 authGateway.addQueryItem(
"source", q->userAgent() );
484 authGateway.addQueryItem(
"service",
"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(
"Auth=(.+)" );
491 if ( rx.indexIn( 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(
"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(
"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[
"id"] = rx.cap( 1 );
557 blogInfo[
"title"] = ( *it )->title();
558 blogInfo[
"url"] = ( *it )->link();
559 blogInfo[
"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(
"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(
"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(
"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(
"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(
"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(
"<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(
"<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(
"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(
"<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(
"<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(
"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(
"<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(
"<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"