summaryrefslogtreecommitdiff
path: root/newtopicaction.cpp
diff options
context:
space:
mode:
authorJavier S. Pedro <maemo@javispedro.com>2013-04-06 21:20:30 +0200
committerJavier S. Pedro <maemo@javispedro.com>2013-04-06 21:20:30 +0200
commitb0886b317fd6de5fa960392b2a8a0dbb557475f5 (patch)
treea2e23cd67c601f2abee84b2d9553436f34716921 /newtopicaction.cpp
parentcb820fa02315cbf5ecc7f87435bc724460104f19 (diff)
downloadtapasboard-b0886b317fd6de5fa960392b2a8a0dbb557475f5.tar.gz
tapasboard-b0886b317fd6de5fa960392b2a8a0dbb557475f5.zip
creating new topics
Diffstat (limited to 'newtopicaction.cpp')
-rw-r--r--newtopicaction.cpp61
1 files changed, 61 insertions, 0 deletions
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 <QtCore/QDebug>
+#include <QtSql/QSqlDatabase>
+#include <QtSql/QSqlQuery>
+
+#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<QVariantMap> 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();
+}