diff options
-rw-r--r-- | board.h | 2 | ||||
-rw-r--r-- | boardmodel.cpp | 10 | ||||
-rw-r--r-- | boardmodel.h | 1 | ||||
-rw-r--r-- | markforumreadaction.cpp | 52 | ||||
-rw-r--r-- | markforumreadaction.h | 26 | ||||
-rw-r--r-- | qml/BoardPage.qml | 15 | ||||
-rw-r--r-- | tapasboard.pro | 6 |
7 files changed, 109 insertions, 3 deletions
@@ -39,7 +39,7 @@ public: int rootForumId() const; // Configuration table - QString getConfig(const QString& key) const; + Q_INVOKABLE QString getConfig(const QString& key) const; void setConfig(const QString& key, const QString &value); // Login/logout stuff diff --git a/boardmodel.cpp b/boardmodel.cpp index 8d37fa5..98c6302 100644 --- a/boardmodel.cpp +++ b/boardmodel.cpp @@ -4,6 +4,7 @@ #include "global.h" #include "board.h" #include "fetchforumsaction.h" +#include "markforumreadaction.h" #include "boardmodel.h" BoardModel::BoardModel(QObject *parent) : @@ -130,6 +131,15 @@ void BoardModel::refresh() } } +void BoardModel::markSubforumsRead() +{ + if (_forumId == 0 || _board->getConfig("mark_forum") == "1") { + _board->enqueueAction(new MarkForumReadAction(_forumId, _board)); + } else { + qWarning() << "Unsupported: marking specific subforum as read"; + } +} + void BoardModel::reload() { beginResetModel(); diff --git a/boardmodel.h b/boardmodel.h index ba4cda9..d945de2 100644 --- a/boardmodel.h +++ b/boardmodel.h @@ -40,6 +40,7 @@ public: public slots: void refresh(); + void markSubforumsRead(); signals: void boardChanged(); diff --git a/markforumreadaction.cpp b/markforumreadaction.cpp new file mode 100644 index 0000000..6829433 --- /dev/null +++ b/markforumreadaction.cpp @@ -0,0 +1,52 @@ +#include <QtCore/QDebug> + +#include "board.h" +#include "xmlrpcinterface.h" +#include "xmlrpcreply.h" +#include "fetchforumsaction.h" +#include "markforumreadaction.h" + +MarkForumReadAction::MarkForumReadAction(int forumId, Board *board) : + Action(board), _forumId(forumId) +{ +} + +bool MarkForumReadAction::isSupersetOf(Action *action) const +{ + MarkForumReadAction *other = qobject_cast<MarkForumReadAction*>(action); + if (other) { + return _forumId == other->_forumId; + } + return false; +} + +void MarkForumReadAction::execute() +{ + if (_forumId == 0) { + _call = _board->service()->asyncCall("mark_all_as_read"); + } else { + _call = _board->service()->asyncCall("mark_all_as_read", QString(_forumId)); + } + _call->setParent(this); + connect(_call, SIGNAL(finished(XmlRpcPendingCall*)), SLOT(handleFinishedCall())); +} + +void MarkForumReadAction::handleFinishedCall() +{ + XmlRpcReply<QVariantMap> result(_call); + if (result.isValid()) { + QVariantMap map = result; + bool result_ok = map["result"].toBool(); + if (result_ok) { + // Must reload forums to see the result! + _board->enqueueAction(new FetchForumsAction(_board)); + } else { + qWarning() << "Failed to mark forums: " << map["result_text"].toString(); + } + } else { + qWarning() << "Could not fetch board configuration"; + // TODO emit error ... + } + emit finished(this); + _call->deleteLater(); +} diff --git a/markforumreadaction.h b/markforumreadaction.h new file mode 100644 index 0000000..1106352 --- /dev/null +++ b/markforumreadaction.h @@ -0,0 +1,26 @@ +#ifndef MARKFORUMREADACTION_H +#define MARKFORUMREADACTION_H + +#include "action.h" + +class XmlRpcPendingCall; + +class MarkForumReadAction : public Action +{ + Q_OBJECT +public: + explicit MarkForumReadAction(int forumId, Board *board); + + bool isSupersetOf(Action *action) const; + + void execute(); + +private slots: + void handleFinishedCall(); + +private: + XmlRpcPendingCall *_call; + int _forumId; +}; + +#endif // MARKFORUMREADACTION_H diff --git a/qml/BoardPage.qml b/qml/BoardPage.qml index ca988f3..63df29e 100644 --- a/qml/BoardPage.qml +++ b/qml/BoardPage.qml @@ -27,6 +27,21 @@ Page { } } } + ToolIcon { + platformIconId: "toolbar-view-menu" + onClicked: (boardMenu.status === DialogStatus.Closed) ? boardMenu.open() : boardMenu.close() + } + } + + Menu { + id: boardMenu + MenuLayout { + MenuItem { + text: boardPage.forumId == 0 ? qsTr("Mark all forums read") : qsTr("Mark subforums read"); + onClicked: boardModel.markSubforumsRead(); + } + } + } ListView { diff --git a/tapasboard.pro b/tapasboard.pro index 4189ff8..33c2306 100644 --- a/tapasboard.pro +++ b/tapasboard.pro @@ -50,7 +50,8 @@ SOURCES += main.cpp \ favoritesmodel.cpp \ imagecache.cpp \ imagenetworkaccessmanager.cpp \ - loginaction.cpp + loginaction.cpp \ + markforumreadaction.cpp HEADERS += \ action.h \ @@ -70,7 +71,8 @@ HEADERS += \ favoritesmodel.h \ imagecache.h \ imagenetworkaccessmanager.h \ - loginaction.h + loginaction.h \ + markforumreadaction.h TRANSLATIONS += i18n/en.ts i18n/es.ts |