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 --- board.cpp | 6 ++++ board.h | 1 + newpostaction.cpp | 1 + newpostaction.h | 1 - newtopicaction.cpp | 61 ++++++++++++++++++++++++++++++++ newtopicaction.h | 28 +++++++++++++++ qml/ForumPage.qml | 10 ++++++ qml/NewTopicSheet.qml | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++ tapasboard.pro | 6 ++-- 9 files changed, 208 insertions(+), 3 deletions(-) create mode 100644 newtopicaction.cpp create mode 100644 newtopicaction.h create mode 100644 qml/NewTopicSheet.qml 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 +#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(); +} 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 -- cgit v1.2.3