summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--board.cpp6
-rw-r--r--board.h2
-rw-r--r--fetchpostsaction.cpp11
-rw-r--r--fetchpostsaction.h1
-rw-r--r--fetchtopicsaction.cpp11
-rw-r--r--fetchtopicsaction.h1
-rw-r--r--forummodel.cpp6
-rw-r--r--global.h3
-rw-r--r--topicmodel.cpp12
-rw-r--r--topicmodel.h2
10 files changed, 37 insertions, 18 deletions
diff --git a/board.cpp b/board.cpp
index bc9f4e7..5878475 100644
--- a/board.cpp
+++ b/board.cpp
@@ -211,7 +211,7 @@ QString Board::renderHumanDate(const QDateTime &dateTime)
}
}
-QString Board::renderHumanTime(const QDateTime &dateTime)
+QString Board::renderHumanDateTime(const QDateTime &dateTime)
{
const QDateTime now = QDateTime::currentDateTime();
QDateTime localDateTime = dateTime.toLocalTime();
@@ -478,7 +478,7 @@ bool Board::cleanDb()
int total_rows = 0;
q.prepare("DELETE FROM topics WHERE last_update_time < ?");
- q.bindValue(0, QDateTime::currentDateTime().addDays(-FORUM_TOPICS_CACHE));
+ q.bindValue(0, QDateTime::currentDateTimeUtc().addDays(-FORUM_TOPICS_CACHE));
if (q.exec()) {
total_rows += q.numRowsAffected();
} else {
@@ -487,7 +487,7 @@ bool Board::cleanDb()
q.prepare("DELETE FROM posts WHERE last_update_time < ?");
- q.bindValue(0, QDateTime::currentDateTime().addDays(-TOPIC_POSTS_CACHE));
+ q.bindValue(0, QDateTime::currentDateTimeUtc().addDays(-TOPIC_POSTS_CACHE));
if (q.exec()) {
total_rows += q.numRowsAffected();
} else {
diff --git a/board.h b/board.h
index eadf4c0..7e8fb97 100644
--- a/board.h
+++ b/board.h
@@ -55,7 +55,7 @@ public:
QString parseSmilies(QString text) const;
QString renderHumanDate(const QDateTime& dateTime);
- QString renderHumanTime(const QDateTime& dateTime);
+ QString renderHumanDateTime(const QDateTime& dateTime);
public slots:
void cancelAllActions();
diff --git a/fetchpostsaction.cpp b/fetchpostsaction.cpp
index 1330f44..dbfaf41 100644
--- a/fetchpostsaction.cpp
+++ b/fetchpostsaction.cpp
@@ -132,9 +132,9 @@ void FetchPostsAction::handleFinishedCall()
query.bindValue(":post_author_name", unencodePostText(post["post_author_name"]));
query.bindValue(":can_edit", post["can_edit"].toBool() ? 1 : 0);
query.bindValue(":icon_url", post["icon_url"].toString());
- query.bindValue(":post_time", post["post_time"].toDateTime());
+ query.bindValue(":post_time", unencodeDateTime(post["post_time"]));
query.bindValue(":position", position);
- query.bindValue(":last_update_time", QDateTime::currentDateTime());
+ query.bindValue(":last_update_time", QDateTime::currentDateTimeUtc());
Q_ASSERT(position < total_post_num);
@@ -197,3 +197,10 @@ QString FetchPostsAction::unencodePostContent(const QVariant &v)
QString richText = _board->bbcodeToRichText(unencodePostText(v));
return _board->parseSmilies(richText);
}
+
+QDateTime FetchPostsAction::unencodeDateTime(const QVariant &v)
+{
+ QDateTime dt = v.toDateTime();
+ dt.setTimeSpec(Qt::UTC);
+ return dt;
+}
diff --git a/fetchpostsaction.h b/fetchpostsaction.h
index 66e6c73..f8ad03e 100644
--- a/fetchpostsaction.h
+++ b/fetchpostsaction.h
@@ -31,6 +31,7 @@ private:
static QString unencodePostText(const QVariant& v);
static QString unencodePostTitle(const QVariant& v, const QString& topicTitle);
QString unencodePostContent(const QVariant& v);
+ static QDateTime unencodeDateTime(const QVariant& v);
private:
XmlRpcPendingCall *_call;
diff --git a/fetchtopicsaction.cpp b/fetchtopicsaction.cpp
index 13aebdd..d71bdca 100644
--- a/fetchtopicsaction.cpp
+++ b/fetchtopicsaction.cpp
@@ -91,11 +91,11 @@ void FetchTopicsAction::handleFinishedCall()
query.bindValue(":is_subscribed", topic["is_subscribed"].toBool() ? 1 : 0);
query.bindValue(":is_closed", topic["is_closed"].toBool() ? 1 : 0);
query.bindValue(":icon_url", topic["icon_url"].toString());
- query.bindValue(":last_reply_time", topic["last_reply_time"].toDateTime());
+ query.bindValue(":last_reply_time", unencodeDateTime(topic["last_reply_time"]));
query.bindValue(":reply_number", topic["reply_number"].toInt());
query.bindValue(":new_post", topic["new_post"].toBool() ? 1 : 0);
query.bindValue(":position", position);
- query.bindValue(":last_update_time", QDateTime::currentDateTime());
+ query.bindValue(":last_update_time", QDateTime::currentDateTimeUtc());
position++;
@@ -135,3 +135,10 @@ QString FetchTopicsAction::unencodeTopicText(const QVariant &v)
QByteArray ba = v.toByteArray();
return QString::fromUtf8(ba.constData(), ba.length());
}
+
+QDateTime FetchTopicsAction::unencodeDateTime(const QVariant &v)
+{
+ QDateTime dt = v.toDateTime();
+ dt.setTimeSpec(Qt::UTC);
+ return dt;
+}
diff --git a/fetchtopicsaction.h b/fetchtopicsaction.h
index 9c12784..0519e0c 100644
--- a/fetchtopicsaction.h
+++ b/fetchtopicsaction.h
@@ -26,6 +26,7 @@ private slots:
private:
static QString unencodeTopicText(const QVariant& v);
+ static QDateTime unencodeDateTime(const QVariant& v);
private:
XmlRpcPendingCall *_call;
diff --git a/forummodel.cpp b/forummodel.cpp
index 7606f93..aecb8c2 100644
--- a/forummodel.cpp
+++ b/forummodel.cpp
@@ -125,7 +125,7 @@ void ForumModel::fetchMore(const QModelIndex &parent)
if (!topics.empty()) {
QDateTime last = oldestPostUpdate(topics);
// If the topics we got from DB are too old, refresh online.
- if (last.secsTo(QDateTime::currentDateTime()) > FORUM_TOPICS_TLL) {
+ if (last.secsTo(QDateTime::currentDateTimeUtc()) > FORUM_TOPICS_TLL) {
qDebug() << "Fetching topics because of old";
Q_ASSERT(new_end > 0);
_board->enqueueAction(new FetchTopicsAction(_forumId,
@@ -163,7 +163,7 @@ QDateTime ForumModel::parseDateTime(const QVariant &v)
QDateTime ForumModel::oldestPostUpdate(const QList<Topic> &topics)
{
- if (topics.empty()) return QDateTime::currentDateTime();
+ if (topics.empty()) return QDateTime::currentDateTimeUtc();
QDateTime min = topics.first().last_update_time;
foreach (const Topic& topic, topics) {
if (min < topic.last_update_time) min = topic.last_update_time;
@@ -299,7 +299,7 @@ void ForumModel::update()
if (!_board->service()->isAccessible()) return;
QDateTime last = lastTopPostUpdate();
if (!last.isValid() ||
- last.secsTo(QDateTime::currentDateTime()) > FORUM_TOP_TLL) {
+ last.secsTo(QDateTime::currentDateTimeUtc()) > FORUM_TOP_TLL) {
// Outdated or empty, refresh.
qDebug() << "Fetching topics because the top are old";
_board->enqueueAction(new FetchTopicsAction(_forumId, 0, FORUM_PAGE_SIZE - 1, _board));
diff --git a/global.h b/global.h
index 8c64a4c..74f972e 100644
--- a/global.h
+++ b/global.h
@@ -6,9 +6,6 @@
/** Time the forum config settings should be considered up to date, in days. */
#define BOARD_CONFIG_TTL 2
-/** Time the forum smilies list should be considered up to date, in days. */
-#define SMILIES_LIST_TTL BOARD_CONFIG_TLL
-
/** Time the list of forums should be considered up to date, in days. */
#define BOARD_LIST_TTL 2
diff --git a/topicmodel.cpp b/topicmodel.cpp
index d3032be..653934a 100644
--- a/topicmodel.cpp
+++ b/topicmodel.cpp
@@ -105,6 +105,8 @@ QVariant TopicModel::data(const QModelIndex &index, int role) const
case HumanDateRole:
case HumanTimeRole:
return QVariant::fromValue(QString());
+ case IconRole:
+ return QVariant::fromValue(QUrl());
case DateTimeRole:
return QVariant::fromValue(QDateTime());
case UnreadRole:
@@ -119,6 +121,8 @@ QVariant TopicModel::data(const QModelIndex &index, int role) const
return _data[row].title;
case ContentRole:
return _data[row].content;
+ case IconRole:
+ return _data[row].icon;
case PostIdRole:
return _data[row].post_id;
case UserIdRole:
@@ -130,7 +134,7 @@ QVariant TopicModel::data(const QModelIndex &index, int role) const
case HumanDateRole:
return _board->renderHumanDate(_data[row].time);
case HumanTimeRole:
- return _board->renderHumanTime(_data[row].time);
+ return _board->renderHumanDateTime(_data[row].time);
case UnreadRole:
return _firstUnread >= 0 && row >= _firstUnread;
}
@@ -168,7 +172,7 @@ void TopicModel::fetchMore(const QModelIndex &parent)
if (!posts.empty()) {
QDateTime last = oldestPostUpdate(posts);
// If the posts we got from DB are too old, refresh online.
- if (last.secsTo(QDateTime::currentDateTime()) > TOPIC_POSTS_TLL) {
+ if (last.secsTo(QDateTime::currentDateTimeUtc()) > TOPIC_POSTS_TLL) {
qDebug() << "Fetching posts because of old";
Q_ASSERT(new_end > 0);
_board->enqueueAction(new FetchPostsAction(_topicId,
@@ -211,7 +215,7 @@ QDateTime TopicModel::parseDbDateTime(const QVariant &v)
QDateTime TopicModel::oldestPostUpdate(const QList<Post> &posts)
{
- if (posts.empty()) return QDateTime::currentDateTime();
+ if (posts.empty()) return QDateTime::currentDateTimeUtc();
QDateTime min = posts.first().last_update_time;
foreach (const Post& post, posts) {
if (min < post.last_update_time) min = post.last_update_time;
@@ -374,7 +378,7 @@ void TopicModel::update()
if (!_board->service()->isAccessible()) return;
QDateTime last = lastTopPostUpdate();
if (!last.isValid() ||
- last.secsTo(QDateTime::currentDateTime()) > TOPIC_TOP_TLL) {
+ last.secsTo(QDateTime::currentDateTimeUtc()) > TOPIC_TOP_TLL) {
qDebug() << "Fetching posts because the top are old";
// Outdated or empty, refresh.
if (_board->loggedIn() && _board->getConfig("goto_unread") == "1") {
diff --git a/topicmodel.h b/topicmodel.h
index d0c60bb..7b07c1b 100644
--- a/topicmodel.h
+++ b/topicmodel.h
@@ -3,6 +3,7 @@
#include <QtCore/QAbstractListModel>
#include <QtCore/QDateTime>
+#include <QtCore/QUrl>
#include <QtSql/QSqlQuery>
class Board;
@@ -60,6 +61,7 @@ protected:
int post_id;
QString title;
QString content;
+ QUrl icon;
int user_id;
QString user_name;
QDateTime time;