void GDataPrivate::slotFetchPost( Syndication::Loader *loader, Syndication::FeedPtr feed, Syndication::ErrorCode status ) { kDebug(); Q_Q( GData ); if( !loader ) { kError() << "loader is a null pointer."; return; } bool success = false; BlogPost *post = mFetchPostMap[ loader ]; if(!post){ kError()<<"returned loader cannot find in requests map."; return; } if ( status != Syndication::Success ) { emit q->errorPost( GData::Atom, i18n( "Could not get posts." ), post ); return; } QList<Syndication::ItemPtr> items = feed->items(); QList<Syndication::ItemPtr>::ConstIterator it = items.constBegin(); QList<Syndication::ItemPtr>::ConstIterator end = items.constEnd(); for ( ; it != end; ++it ) { QRegExp rx( "post-(\\d+)" ); if ( rx.indexIn( ( *it )->id() ) != -1 && rx.cap(1) == post->postId() ){ kDebug() << "QRegExp rx( 'post-(\\d+)' matches" << rx.cap(1); post->setPostId( rx.cap(1) ); post->setTitle( ( *it )->title() ); post->setContent( ( *it )->content() ); post->setStatus( BlogPost::Fetched ); post->setLink( ( *it )->link() ); // FIXME: assuming UTC for now post->setCreationDateTime( KDateTime( QDateTime::fromTime_t( ( *it )->datePublished() ), KDateTime::Spec::UTC() ).toLocalZone() ); post->setModificationDateTime( KDateTime( QDateTime::fromTime_t( ( *it )->dateUpdated() ), KDateTime::Spec::UTC() ).toLocalZone() ); kDebug() << "Emitting fetchedPost( postId=" << post->postId() << ");"; success = true; emit q->fetchedPost( post ); } } if ( !success ) { kError() << "QRegExp rx( 'post-(\\d+)' does not match" << mFetchPostMap[ loader ]->postId() << "."; emit q->errorPost( GData::Other, i18n( "Could not regexp the blog id path." ), post ); } mFetchPostMap.remove( loader ); }
void GDataPrivate::slotListComments( Syndication::Loader *loader, Syndication::FeedPtr feed, Syndication::ErrorCode status ) { kDebug(); Q_Q( GData ); if( !loader ) { kError() << "loader is a null pointer."; return; } BlogPost *post = mListCommentsMap[ loader ]; mListCommentsMap.remove( loader ); if ( status != Syndication::Success ) { emit q->errorPost( GData::Atom, i18n( "Could not get comments." ), post ); return; } QList<KBlog::BlogComment> commentList; QList<Syndication::ItemPtr> items = feed->items(); QList<Syndication::ItemPtr>::ConstIterator it = items.constBegin(); QList<Syndication::ItemPtr>::ConstIterator end = items.constEnd(); for ( ; it != end; ++it ) { BlogComment comment; QRegExp rx( "post-(\\d+)" ); if ( rx.indexIn( ( *it )->id() ) == -1 ) { kError() << "QRegExp rx( 'post-(\\d+)' does not match" << rx.cap(1); emit q->error( GData::Other, i18n( "Could not regexp the comment id path." ) ); } else { comment.setCommentId( rx.cap(1) ); } kDebug() << "QRegExp rx( 'post-(\\d+)' matches" << rx.cap(1); comment.setTitle( ( *it )->title() ); comment.setContent( ( *it )->content() ); // FIXME: assuming UTC for now comment.setCreationDateTime( KDateTime( QDateTime::fromTime_t( ( *it )->datePublished() ), KDateTime::Spec::UTC() ) ); comment.setModificationDateTime( KDateTime( QDateTime::fromTime_t( ( *it )->dateUpdated() ), KDateTime::Spec::UTC() ) ); commentList.append( comment ); } kDebug() << "Emitting listedComments()"; emit q->listedComments( post, commentList ); }
void GDataPrivate::slotListBlogs( Syndication::Loader *loader, Syndication::FeedPtr feed, Syndication::ErrorCode status ) { kDebug(); Q_Q( GData ); if( !loader ) { kError() << "loader is a null pointer."; return; } if ( status != Syndication::Success ) { emit q->error( GData::Atom, i18n( "Could not get blogs." ) ); return; } QList<QMap<QString,QString> > blogsList; QList<Syndication::ItemPtr> items = feed->items(); QList<Syndication::ItemPtr>::ConstIterator it = items.constBegin(); QList<Syndication::ItemPtr>::ConstIterator end = items.constEnd(); for ( ; it != end; ++it ) { QRegExp rx( "blog-(\\d+)" ); QMap<QString,QString> blogInfo; if ( rx.indexIn( ( *it )->id() ) != -1 ) { kDebug() << "QRegExp rx( 'blog-(\\d+)' matches" << rx.cap(1); blogInfo["id"] = rx.cap(1); blogInfo["title"] = ( *it )->title(); blogInfo["url"] = ( *it )->link(); blogInfo["summary"] = ( *it )->description(); //TODO fix/add more blogsList << blogInfo; } else { kError() << "QRegExp rx( 'blog-(\\d+)' does not match anything in:" << ( *it )->id(); emit q->error( GData::Other, i18n( "Could not regexp the blog id path." ) ); } } kDebug() << "Emitting listedBlogs(); "; emit q->listedBlogs( blogsList ); }
void Feed::appendArticles(const Syndication::FeedPtr feed) { d->setTotalCountDirty(); bool changed = false; const bool notify = useNotification() || Settings::useNotifications(); QList<ItemPtr> items = feed->items(); QList<ItemPtr>::ConstIterator it = items.constBegin(); QList<ItemPtr>::ConstIterator en = items.constEnd(); int nudge=0; QList<Article> deletedArticles = d->deletedArticles; for ( ; it != en; ++it) { if ( !d->articles.contains((*it)->id()) ) // article not in list { Article mya(*it, this); mya.offsetPubDate(nudge); nudge--; appendArticle(mya); d->addedArticlesNotify.append(mya); if (!mya.isDeleted() && !markImmediatelyAsRead()) mya.setStatus(New); else mya.setStatus(Read); if ( notify ) NotificationManager::self()->slotNotifyArticle( mya ); changed = true; } else // article is in list { // if the article's guid is no hash but an ID, we have to check if the article was updated. That's done by comparing the hash values. Article old = d->articles[(*it)->id()]; Article mya(*it, this); if (!mya.guidIsHash() && mya.hash() != old.hash() && !old.isDeleted()) { mya.setKeep(old.keep()); int oldstatus = old.status(); old.setStatus(Read); d->articles.remove(old.guid()); appendArticle(mya); mya.setStatus(oldstatus); d->updatedArticlesNotify.append(mya); changed = true; } else if (old.isDeleted()) deletedArticles.removeAll(mya); } } QList<Article>::ConstIterator dit = deletedArticles.constBegin(); QList<Article>::ConstIterator dtmp; QList<Article>::ConstIterator den = deletedArticles.constEnd(); // delete articles with delete flag set completely from archive, which aren't in the current feed source anymore while (dit != den) { dtmp = dit; ++dit; d->articles.remove((*dtmp).guid()); d->archive->deleteArticle((*dtmp).guid()); d->removedArticlesNotify.append( *dtmp ); changed = true; d->deletedArticles.removeAll(*dtmp); } if (changed) articlesModified(); }
void GDataPrivate::slotListRecentPosts( Syndication::Loader *loader, Syndication::FeedPtr feed, Syndication::ErrorCode status ) { kDebug(); Q_Q( GData ); if( !loader ) { kError() << "loader is a null pointer."; return; } if ( status != Syndication::Success ) { emit q->error( GData::Atom, i18n( "Could not get posts." ) ); return; } int number = 0; if ( mListRecentPostsMap.contains( loader ) ) { number = mListRecentPostsMap[ loader ]; } mListRecentPostsMap.remove( loader ); QList<KBlog::BlogPost> postList; QList<Syndication::ItemPtr> items = feed->items(); QList<Syndication::ItemPtr>::ConstIterator it = items.constBegin(); QList<Syndication::ItemPtr>::ConstIterator end = items.constEnd(); for ( ; it != end; ++it ) { BlogPost post; QRegExp rx( "post-(\\d+)" ); if ( rx.indexIn( ( *it )->id() ) == -1 ) { kError() << "QRegExp rx( 'post-(\\d+)' does not match"<< rx.cap(1); emit q->error( GData::Other, i18n( "Could not regexp the post id path." ) ); } else { post.setPostId( rx.cap(1) ); } kDebug() << "QRegExp rx( 'post-(\\d+)' matches" << rx.cap(1); post.setTitle( ( *it )->title() ); post.setContent( ( *it )->content() ); post.setLink( ( *it )->link() ); QStringList labels; int catCount = ( *it )->categories().count(); QList< Syndication::CategoryPtr > cats = ( *it )->categories(); for(int i=0; i < catCount; ++i) { if(cats[i].get()->label().isEmpty()){ labels.append(cats[i].get()->term()); } else { labels.append(cats[i].get()->label()); } } post.setTags(labels); // FIXME: assuming UTC for now post.setCreationDateTime( KDateTime( QDateTime::fromTime_t( ( *it )->datePublished() ), KDateTime::Spec::UTC() ).toLocalZone() ); post.setModificationDateTime( KDateTime( QDateTime::fromTime_t( ( *it )->dateUpdated() ), KDateTime::Spec::UTC() ).toLocalZone() ); post.setStatus( BlogPost::Fetched ); postList.append( post ); if ( number-- == 0 ) { break; } } kDebug() << "Emitting listedRecentPosts()"; emit q->listedRecentPosts( postList ); }