summaryrefslogtreecommitdiff
path: root/forummodel.h
diff options
context:
space:
mode:
Diffstat (limited to 'forummodel.h')
-rw-r--r--forummodel.h72
1 files changed, 72 insertions, 0 deletions
diff --git a/forummodel.h b/forummodel.h
new file mode 100644
index 0000000..8cde5cf
--- /dev/null
+++ b/forummodel.h
@@ -0,0 +1,72 @@
+#ifndef FORUMMODEL_H
+#define FORUMMODEL_H
+
+#include <QtCore/QAbstractListModel>
+#include <QtCore/QDateTime>
+#include <QtSql/QSqlQuery>
+
+class Board;
+
+class ForumModel : public QAbstractListModel
+{
+ Q_OBJECT
+ Q_PROPERTY(QString boardUrl READ boardUrl WRITE setBoardUrl NOTIFY boardUrlChanged)
+ Q_PROPERTY(int forumId READ forumId WRITE setForumId NOTIFY forumIdChanged)
+
+public:
+ ForumModel(QObject *parent = 0);
+
+ enum DataRoles {
+ TitleRole = Qt::DisplayRole,
+ IconRole = Qt::DecorationRole,
+
+ TopicIdRole = Qt::UserRole,
+ TopicTypeRole
+ };
+
+ QString boardUrl() const;
+ void setBoardUrl(const QString& url);
+
+ int forumId() const;
+ void setForumId(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 forumIdChanged();
+
+protected:
+ struct Topic {
+ int topic_id;
+ QString title;
+ QDateTime last_reply_time;
+ QDateTime last_update_time;
+ };
+
+private:
+ static QDateTime parseDateTime(const QVariant& v);
+ static QDateTime oldestPostUpdate(const QList<Topic>& topics);
+ QDateTime lastTopPostUpdate();
+ QList<Topic> loadTopics(int start, int end);
+ void clearModel();
+
+private slots:
+ void handleForumTopicsChanged(int forumId, int start, int end);
+ void update();
+ void reload();
+
+private:
+ QString _boardUrl;
+ Board *_board;
+ int _forumId;
+ QList<Topic> _data;
+ bool _eof;
+};
+
+
+#endif // FORUMMODEL_H