summaryrefslogtreecommitdiff
path: root/markforumreadaction.cpp
diff options
context:
space:
mode:
authorJavier S. Pedro <maemo@javispedro.com>2013-04-04 22:21:03 +0200
committerJavier S. Pedro <maemo@javispedro.com>2013-04-04 22:21:03 +0200
commit3f3a98b7e49230aabd0e557ea59e89e20537ca8a (patch)
tree3bcd3ca91be37e3d5a7afceb1e3c32e77c72f689 /markforumreadaction.cpp
parentd69a9c6657efb6f49b882cbf17ca0d83ca74e17a (diff)
downloadtapasboard-3f3a98b7e49230aabd0e557ea59e89e20537ca8a.tar.gz
tapasboard-3f3a98b7e49230aabd0e557ea59e89e20537ca8a.zip
add support to mark forums as read
Diffstat (limited to 'markforumreadaction.cpp')
-rw-r--r--markforumreadaction.cpp52
1 files changed, 52 insertions, 0 deletions
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 <QtCore/QDebug>
+
+#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<MarkForumReadAction*>(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<QVariantMap> 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();
+}