From 3f3a98b7e49230aabd0e557ea59e89e20537ca8a Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Thu, 4 Apr 2013 22:21:03 +0200 Subject: add support to mark forums as read --- markforumreadaction.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 markforumreadaction.cpp (limited to 'markforumreadaction.cpp') diff --git a/markforumreadaction.cpp b/markforumreadaction.cpp new file mode 100644 index 0000000..6829433 --- /dev/null +++ b/markforumreadaction.cpp @@ -0,0 +1,52 @@ +#include + +#include "board.h" +#include "xmlrpcinterface.h" +#include "xmlrpcreply.h" +#include "fetchforumsaction.h" +#include "markforumreadaction.h" + +MarkForumReadAction::MarkForumReadAction(int forumId, Board *board) : + Action(board), _forumId(forumId) +{ +} + +bool MarkForumReadAction::isSupersetOf(Action *action) const +{ + MarkForumReadAction *other = qobject_cast(action); + if (other) { + return _forumId == other->_forumId; + } + return false; +} + +void MarkForumReadAction::execute() +{ + if (_forumId == 0) { + _call = _board->service()->asyncCall("mark_all_as_read"); + } else { + _call = _board->service()->asyncCall("mark_all_as_read", QString(_forumId)); + } + _call->setParent(this); + connect(_call, SIGNAL(finished(XmlRpcPendingCall*)), SLOT(handleFinishedCall())); +} + +void MarkForumReadAction::handleFinishedCall() +{ + XmlRpcReply result(_call); + if (result.isValid()) { + QVariantMap map = result; + bool result_ok = map["result"].toBool(); + if (result_ok) { + // Must reload forums to see the result! + _board->enqueueAction(new FetchForumsAction(_board)); + } else { + qWarning() << "Failed to mark forums: " << map["result_text"].toString(); + } + } else { + qWarning() << "Could not fetch board configuration"; + // TODO emit error ... + } + emit finished(this); + _call->deleteLater(); +} -- cgit v1.2.3