diff options
author | Javier S. Pedro <maemo@javispedro.com> | 2013-04-01 20:46:39 +0200 |
---|---|---|
committer | Javier S. Pedro <maemo@javispedro.com> | 2013-04-01 20:46:39 +0200 |
commit | a6e64fbf9404b201b04fbd1ab4b959a18d8f83a9 (patch) | |
tree | 6b97b6ac14716dbe51cb105819abde3e36ffd465 /topicmodel.h | |
parent | 5ef8b38e55c1883224fe1f01f47aba45b7b42666 (diff) | |
download | tapasboard-a6e64fbf9404b201b04fbd1ab4b959a18d8f83a9.tar.gz tapasboard-a6e64fbf9404b201b04fbd1ab4b959a18d8f83a9.zip |
add support for actually reading topics
Diffstat (limited to 'topicmodel.h')
-rw-r--r-- | topicmodel.h | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/topicmodel.h b/topicmodel.h new file mode 100644 index 0000000..95a3f78 --- /dev/null +++ b/topicmodel.h @@ -0,0 +1,72 @@ +#ifndef TOPICMODEL_H +#define TOPICMODEL_H + +#include <QtCore/QAbstractListModel> +#include <QtCore/QDateTime> +#include <QtSql/QSqlQuery> + +class Board; + +class TopicModel : public QAbstractListModel +{ + Q_OBJECT + Q_PROPERTY(QString boardUrl READ boardUrl WRITE setBoardUrl NOTIFY boardUrlChanged) + Q_PROPERTY(int topicId READ topicId WRITE setTopicId NOTIFY topicIdChanged) + +public: + TopicModel(QObject *parent = 0); + + enum DataRoles { + TitleRole = Qt::DisplayRole, + IconRole = Qt::DecorationRole, + ContentRole = Qt::ToolTipRole, + + PostIdRole = Qt::UserRole + }; + + QString boardUrl() const; + void setBoardUrl(const QString& url); + + int topicId() const; + void setTopicId(const int id); + + int rowCount(const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role) const; + + bool canFetchMore(const QModelIndex &parent = QModelIndex()) const; + void fetchMore(const QModelIndex &parent = QModelIndex()); + +signals: + void boardUrlChanged(); + void topicIdChanged(); + +protected: + struct Post { + int post_id; + QString title; + QString content; + QDateTime time; + QDateTime last_update_time; + }; + +private: + static QDateTime parseDateTime(const QVariant& v); + static QDateTime oldestPostUpdate(const QList<Post>& posts); + QDateTime lastTopPostUpdate(); + QList<Post> loadPosts(int start, int end); + void clearModel(); + +private slots: + void handleTopicPostsChanged(int forumId, int start, int end); + void update(); + void reload(); + +private: + QString _boardUrl; + Board *_board; + int _topicId; + QList<Post> _data; + bool _eof; +}; + +#endif // TOPICMODEL_H |