summaryrefslogtreecommitdiff
path: root/forummodel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'forummodel.cpp')
-rw-r--r--forummodel.cpp34
1 files changed, 27 insertions, 7 deletions
diff --git a/forummodel.cpp b/forummodel.cpp
index faf0b75..7606f93 100644
--- a/forummodel.cpp
+++ b/forummodel.cpp
@@ -28,6 +28,7 @@ void ForumModel::setBoard(Board *board)
{
if (_board != board) {
disconnect(this, SLOT(handleForumTopicsChanged(int,int,int)));
+ disconnect(this, SLOT(handleForumTopicChanged(int,int)));
clearModel();
_board = board;
@@ -35,6 +36,8 @@ void ForumModel::setBoard(Board *board)
if (_board) {
connect(_board, SIGNAL(forumTopicsChanged(int,int,int)),
SLOT(handleForumTopicsChanged(int,int,int)));
+ connect(_board, SIGNAL(forumTopicChanged(int,int)),
+ SLOT(handleForumTopicChanged(int,int)));
if (_forumId >= 0) {
update();
reload();
@@ -175,7 +178,7 @@ QDateTime ForumModel::lastTopPostUpdate()
QSqlQuery query(db);
query.prepare("SELECT last_update_time FROM topics "
"WHERE forum_id = :forum_id "
- "ORDER BY last_reply_time DESC "
+ "ORDER BY position ASC "
"LIMIT 1");
query.bindValue(":forum_id", _forumId);
if (query.exec()) {
@@ -191,18 +194,16 @@ QDateTime ForumModel::lastTopPostUpdate()
QList<ForumModel::Topic> ForumModel::loadTopics(int start, int end)
{
Q_ASSERT(_board);
- const int rows = end - start + 1;
QList<Topic> topics;
QSqlQuery query(_board->database());
query.prepare("SELECT topic_id, topic_title, reply_number, new_post, last_reply_time, last_update_time FROM topics "
- "WHERE forum_id = :forum_id "
- "ORDER by last_reply_time DESC "
- "LIMIT :start, :limit");
+ "WHERE forum_id = :forum_id AND position BETWEEN :start AND :end "
+ "ORDER by position ASC ");
query.bindValue(":forum_id", _forumId);
query.bindValue(":start", start);
- query.bindValue(":limit", rows);
+ query.bindValue(":end", end);
if (query.exec()) {
- topics.reserve(rows);
+ topics.reserve(end - start + 1);
while (query.next()) {
Topic topic;
topic.topic_id = query.value(0).toInt();
@@ -272,6 +273,25 @@ void ForumModel::handleForumTopicsChanged(int forumId, int start, int end)
}
}
+void ForumModel::handleForumTopicChanged(int forumId, int topicId)
+{
+ if (forumId == _forumId) {qDebug() << "Me topic cha";
+ for (int i = 0; i < _data.size(); i++) {
+ Topic& topic = _data[i];
+ if (topic.topic_id == topicId) {qDebug() << "Me topic cha cha";
+ // Need to refresh this topic
+ QList<Topic> topics = loadTopics(i, i);
+ if (topics.size() == 1) {
+ _data[i] = topics[0];
+ emit dataChanged(createIndex(i, 0), createIndex(i, 0));
+ } else {
+ qWarning() << "Topic changed yet not in DB";
+ }
+ }
+ }
+ }
+}
+
void ForumModel::update()
{
if (!_board || _forumId < 0) return;