diff options
author | Javier S. Pedro <maemo@javispedro.com> | 2013-04-04 01:15:54 +0200 |
---|---|---|
committer | Javier S. Pedro <maemo@javispedro.com> | 2013-04-04 01:15:54 +0200 |
commit | 3c88a76b1be759d13097810877d6e990b3371726 (patch) | |
tree | dd5627700ef12be7c55d9f3ceda5a9575691a337 /fetchtopicsaction.cpp | |
parent | 723e0e7f37636379f76008582dca459490b845f4 (diff) | |
download | tapasboard-3c88a76b1be759d13097810877d6e990b3371726.tar.gz tapasboard-3c88a76b1be759d13097810877d6e990b3371726.zip |
implement refresh action
Diffstat (limited to 'fetchtopicsaction.cpp')
-rw-r--r-- | fetchtopicsaction.cpp | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/fetchtopicsaction.cpp b/fetchtopicsaction.cpp index ead8d4d..bc94965 100644 --- a/fetchtopicsaction.cpp +++ b/fetchtopicsaction.cpp @@ -3,6 +3,7 @@ #include <QtSql/QSqlDatabase> #include <QtSql/QSqlQuery> +#include "global.h" #include "board.h" #include "xmlrpcinterface.h" #include "xmlrpcreply.h" @@ -18,7 +19,18 @@ bool FetchTopicsAction::isSupersetOf(Action *action) const FetchTopicsAction *other = qobject_cast<FetchTopicsAction*>(action); if (other) { if (other->_forumId == _forumId) { - if (_start <= other->_start && _end >= other->_end) { + if (_end == FetchAllTopics) { + // If this is fetching all topics, then this is a superset + // of every other action... except those that also fetch all + // topics. + return other->_end != FetchAllTopics; + } else if (other->_end == FetchAllTopics) { + // If the other action fetches all topics, this cannot be a + // superset + return false; + } else if (_start <= other->_start && _end >= other->_end) { + // Otherwise, check if the range of posts fetched by this + // action fully contains the other action. return true; } } @@ -28,8 +40,15 @@ bool FetchTopicsAction::isSupersetOf(Action *action) const void FetchTopicsAction::execute() { + int end = _end; + if (end == FetchAllTopics) { + // Fetch topics in blocks of size 50. + end = _start + MAX_FORUM_PAGE_SIZE; + // After finishing this action, a new one will be enqueued with the next 50. + } + _call = _board->service()->asyncCall("get_topic", - QString::number(_forumId), _start, _end); + QString::number(_forumId), _start, end); _call->setParent(this); connect(_call, SIGNAL(finished(XmlRpcPendingCall*)), SLOT(handleFinishedCall())); } @@ -85,8 +104,12 @@ void FetchTopicsAction::handleFinishedCall() if (topics.size() > 0) { _board->notifyForumTopicsChanged(_forumId, _start, _start + topics.size() - 1); - } else { - qWarning() << "Asked for topics, got none..."; + } + if (_end == FetchAllTopics && topics.size() == MAX_FORUM_PAGE_SIZE) { + // Ok, let's prepare to fetch the next block of topics because + // there are probably more of them + int start = _start + MAX_FORUM_PAGE_SIZE; + _board->enqueueAction(new FetchTopicsAction(_forumId, start, FetchAllTopics, _board)); } } else { qWarning() << "Could not fetch topics"; |