summaryrefslogtreecommitdiff
path: root/board.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'board.cpp')
-rw-r--r--board.cpp42
1 files changed, 38 insertions, 4 deletions
diff --git a/board.cpp b/board.cpp
index fc5db62..7766088 100644
--- a/board.cpp
+++ b/board.cpp
@@ -21,7 +21,8 @@ Board::Board(QObject *parent) :
Board::Board(const QUrl& url, const QString& username, const QString& password, QObject *parent) :
QObject(parent), _url(url), _slug(createSlug(url)),
_db(QSqlDatabase::addDatabase("QSQLITE", _slug)),
- _iface(new XmlRpcInterface(QUrl(_url), this))
+ _iface(new XmlRpcInterface(QUrl(_url), this)),
+ _markReadDelay(new QTimer(this))
{
_db.setDatabaseName(QDir::toNativeSeparators(getDbPathFor(_slug)));
qDebug() << "Opening database file" << _db.databaseName() << "for" << _url;
@@ -47,6 +48,7 @@ Board::Board(const QUrl& url, const QString& username, const QString& password,
fetchForumsIfOutdated();
initializeBbCode(); // TODO This might depend on board config
initializeSmilies();
+ initializeMarkRead();
}
Board::~Board()
@@ -210,7 +212,18 @@ QString Board::renderHumanDate(const QDateTime &dateTime)
QString Board::renderHumanTime(const QDateTime &dateTime)
{
- return dateTime.toLocalTime().time().toString(Qt::DefaultLocaleShortDate);
+ QDateTime localDateTime = dateTime.toLocalTime();
+ const int secs = localDateTime.secsTo(QDateTime::currentDateTime());
+ if (secs < 1) {
+ return tr("Just now");
+ } else if (secs < 60) {
+ return tr("%n second(s) ago", 0, secs);
+ } else if (secs < 3600) {
+ int mins = (secs + 10) / 3600; // + 10 to round a bit
+ return tr("%n minute(s) ago", 0, mins);
+ } else {
+ return localDateTime.time().toString(Qt::DefaultLocaleShortDate);
+ }
}
void Board::cancelAllActions()
@@ -243,16 +256,22 @@ void Board::notifyForumsChanged()
void Board::notifyForumTopicsChanged(int forumId, int start, int end)
{
- qDebug() << "ForumTopics Changed" << forumId << start << end;
+ qDebug() << "ForumTopics changed" << forumId << start << end;
emit forumTopicsChanged(forumId, start, end);
}
void Board::notifyTopicPostsChanged(int topicId, int start, int end)
{
- qDebug() << "TopicPosts Changed" << topicId << start << end;
+ qDebug() << "TopicPosts changed" << topicId << start << end;
emit topicPostsChanged(topicId, start, end);
}
+void Board::notifyTopicPostsUnread(int topicId, int position)
+{
+ qDebug() << "TopicPosts unread" << topicId << position;
+ emit topicPostsUnread(topicId, position);
+}
+
void Board::notifyLogin(const QMap<QString, QVariant> &info)
{
if (_loginInfo.empty()) {
@@ -281,6 +300,14 @@ void Board::notifyLogout()
}
}
+void Board::markPostAsRead(int postId)
+{
+ _postsToMarkRead.insert(postId);
+ if (!_markReadDelay->isActive()) {
+ _markReadDelay->start();
+ }
+}
+
QString Board::createSlug(const QUrl& url)
{
static const QRegExp regexp("[^a-z0-9]+");
@@ -490,6 +517,13 @@ void Board::initializeSmilies()
Q_ASSERT(_smilieRegexp.isValid());
}
+void Board::initializeMarkRead()
+{
+ _markReadDelay->setInterval(1000); // 1 sec
+ _markReadDelay->setSingleShot(true);
+ // TODO connect
+}
+
void Board::fetchConfigIfOutdated()
{
if (_iface->isAccessible()) {