From b0886b317fd6de5fa960392b2a8a0dbb557475f5 Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Sat, 6 Apr 2013 21:20:30 +0200 Subject: creating new topics --- newtopicaction.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 newtopicaction.cpp (limited to 'newtopicaction.cpp') diff --git a/newtopicaction.cpp b/newtopicaction.cpp new file mode 100644 index 0000000..b984c15 --- /dev/null +++ b/newtopicaction.cpp @@ -0,0 +1,61 @@ +#include +#include +#include + +#include "global.h" +#include "board.h" +#include "xmlrpcinterface.h" +#include "xmlrpcreply.h" +#include "newtopicaction.h" +#include "fetchtopicsaction.h" + +NewTopicAction::NewTopicAction(int forumId, const QString &subject, const QString &text, Board *board) + : Action(board), _forumId(forumId), _subject(subject), _text(text) +{ +} + +bool NewTopicAction::isSupersetOf(Action *action) const +{ + Q_UNUSED(action); + return false; +} + +void NewTopicAction::execute() +{ + _call = _board->service()->asyncCall("new_topic", + QString::number(_forumId), + _subject.toUtf8(), + _text.toUtf8() + ); + _call->setParent(this); + connect(_call, SIGNAL(finished(XmlRpcPendingCall*)), SLOT(handleFinishedCall())); +} + +void NewTopicAction::handleFinishedCall() +{ + XmlRpcReply result(_call); + if (result.isValid()) { + QVariantMap map = result; + bool post_ok = map["result"].toBool(); + if (post_ok) { + int state = map["state"].toInt(); + if (state == 1) { + // Awaiting moderation + // TODO + } else { + // Refresh topics + _board->enqueueAction(new FetchTopicsAction(_forumId, + 0, + FORUM_PAGE_SIZE, + _board)); + } + } else { + qWarning() << "Could not submit topic:" << map["result_text"].toString(); + } + } else { + qWarning() << "Could not submit topic"; + // TODO emit error ... + } + emit finished(this); + _call->deleteLater(); +} -- cgit v1.2.3