summaryrefslogtreecommitdiff
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
parentcb820fa02315cbf5ecc7f87435bc724460104f19 (diff)
downloadtapasboard-b0886b317fd6de5fa960392b2a8a0dbb557475f5.tar.gz
tapasboard-b0886b317fd6de5fa960392b2a8a0dbb557475f5.zip
creating new topics
-rw-r--r--board.cpp6
-rw-r--r--board.h1
-rw-r--r--newpostaction.cpp1
-rw-r--r--newpostaction.h1
-rw-r--r--newtopicaction.cpp61
-rw-r--r--newtopicaction.h28
-rw-r--r--qml/ForumPage.qml10
-rw-r--r--qml/NewTopicSheet.qml97
-rw-r--r--tapasboard.pro6
9 files changed, 208 insertions, 3 deletions
diff --git a/board.cpp b/board.cpp
index 7e734cb..5a755c7 100644
--- a/board.cpp
+++ b/board.cpp
@@ -9,6 +9,7 @@
#include "fetchconfigaction.h"
#include "fetchforumsaction.h"
#include "loginaction.h"
+#include "newtopicaction.h"
#include "newpostaction.h"
#include "xmlrpcinterface.h"
#include "board.h"
@@ -169,6 +170,11 @@ int Board::getTopicForumId(int topicId)
return -1;
}
+void Board::newTopic(int forumId, const QString &subject, const QString &text)
+{
+ enqueueAction(new NewTopicAction(forumId, subject, text, this));
+}
+
void Board::replyToTopic(int topicId, const QString &text)
{
enqueueAction(new NewPostAction(topicId, text, this));
diff --git a/board.h b/board.h
index e48dd6f..81ee81f 100644
--- a/board.h
+++ b/board.h
@@ -52,6 +52,7 @@ public:
int getTopicForumId(int topicId);
// Posting stuff
+ Q_INVOKABLE void newTopic(int forumId, const QString& subject, const QString& text);
Q_INVOKABLE void replyToTopic(int topicId, const QString& text);
// BBCode-related helper functions
diff --git a/newpostaction.cpp b/newpostaction.cpp
index 4ad6244..d2886a6 100644
--- a/newpostaction.cpp
+++ b/newpostaction.cpp
@@ -16,6 +16,7 @@ NewPostAction::NewPostAction(int topicId, const QString &text, Board *board)
bool NewPostAction::isSupersetOf(Action *action) const
{
+ Q_UNUSED(action);
return false;
}
diff --git a/newpostaction.h b/newpostaction.h
index 27896df..7d046d9 100644
--- a/newpostaction.h
+++ b/newpostaction.h
@@ -24,5 +24,4 @@ private:
QString _text;
};
-
#endif // NEWPOSTACTION_H
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();
+}
diff --git a/newtopicaction.h b/newtopicaction.h
new file mode 100644
index 0000000..a04483c
--- /dev/null
+++ b/newtopicaction.h
@@ -0,0 +1,28 @@
+#ifndef NEWTOPICACTION_H
+#define NEWTOPICACTION_H
+
+#include "action.h"
+
+class XmlRpcPendingCall;
+
+class NewTopicAction : public Action
+{
+ Q_OBJECT
+public:
+ explicit NewTopicAction(int forumId, const QString& subject, const QString& text, Board *board);
+
+ bool isSupersetOf(Action *action) const;
+
+ void execute();
+
+private slots:
+ void handleFinishedCall();
+
+private:
+ XmlRpcPendingCall *_call;
+ int _forumId;
+ QString _subject;
+ QString _text;
+};
+
+#endif // NEWTOPICACTION_H
diff --git a/qml/ForumPage.qml b/qml/ForumPage.qml
index 4f2b64f..6c21742 100644
--- a/qml/ForumPage.qml
+++ b/qml/ForumPage.qml
@@ -19,6 +19,16 @@ Page {
}
ToolIcon {
platformIconId: "toolbar-add"
+ onClicked: {
+ var component = Qt.createComponent("NewTopicSheet.qml");
+ if (component.status === Component.Ready) {
+ var sheet = component.createObject(forumPage, {
+ "board": board,
+ "forumId": forumId
+ });
+ sheet.open();
+ }
+ }
}
ToolIcon {
platformIconId: board.busy ? "toolbar-cancle" : "toolbar-refresh"
diff --git a/qml/NewTopicSheet.qml b/qml/NewTopicSheet.qml
new file mode 100644
index 0000000..76cac64
--- /dev/null
+++ b/qml/NewTopicSheet.qml
@@ -0,0 +1,97 @@
+import QtQuick 1.1
+import com.nokia.meego 1.1
+import com.nokia.extras 1.1
+import com.javispedro.tapasboard 1.0
+
+Sheet {
+ id: newTopicSheet
+
+ property Board board;
+ property int forumId;
+
+ anchors.leftMargin: UiConstants.DefaultMargin
+ anchors.rightMargin: UiConstants.DefaultMargin
+
+ acceptButtonText: qsTr("Submit")
+ rejectButtonText: qsTr("Cancel")
+
+ content: Flickable {
+ anchors.fill: parent
+ contentWidth: parent.width
+ contentHeight: subjectLine.height + postText.height
+
+ Item {
+ id: subjectLine
+ anchors {
+ top: parent.top
+ left: parent.left
+ right: parent.right
+ }
+ height: childrenRect.height - 1
+
+ Label {
+ id: subjectLabel
+ anchors {
+ margins: UiConstants.DefaultMargin - 2
+ top: parent.top
+ left: parent.left
+ }
+ text: qsTr("Subject:")
+ }
+
+ TextArea {
+ id: subjectText
+ anchors {
+ top: parent.top
+ left: subjectLabel.right
+ right: parent.right
+ }
+
+ platformStyle: TextAreaStyle {
+ background: ""
+ backgroundSelected: ""
+ backgroundDisabled: ""
+ textFont.bold: true
+ }
+
+ placeholderText: qsTr("Write subject here")
+ wrapMode: TextEdit.Wrap
+ }
+
+
+ BorderImage {
+ anchors {
+ top: subjectText.bottom
+ left: parent.left
+ right: parent.right
+ }
+
+ height: 3
+ source: "image://theme/meegotouch-sheet-editor-collapsed-background"
+ }
+ }
+
+ TextArea {
+ id: postText
+ anchors {
+ top: subjectLine.bottom
+ left: parent.left
+ right: parent.right
+ }
+ height: Math.max(400, implicitHeight)
+
+ platformStyle: TextAreaStyle {
+ background: "image://theme/meegotouch-sheet-inputfield-background"
+ backgroundSelected: background
+ backgroundDisabled: ""
+ }
+
+ placeholderText: qsTr("Write your message here")
+ wrapMode: TextEdit.Wrap
+ }
+ }
+
+ onAccepted: {
+ board.newTopic(forumId, subjectText.text, postText.text);
+ }
+}
diff --git a/tapasboard.pro b/tapasboard.pro
index 4772169..cb502e3 100644
--- a/tapasboard.pro
+++ b/tapasboard.pro
@@ -52,7 +52,8 @@ SOURCES += main.cpp \
imagenetworkaccessmanager.cpp \
loginaction.cpp \
markforumreadaction.cpp \
- newpostaction.cpp
+ newpostaction.cpp \
+ newtopicaction.cpp
HEADERS += \
action.h \
@@ -74,7 +75,8 @@ HEADERS += \
imagenetworkaccessmanager.h \
loginaction.h \
markforumreadaction.h \
- newpostaction.h
+ newpostaction.h \
+ newtopicaction.h
TRANSLATIONS += i18n/en.ts i18n/es.ts