1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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();
}
|