summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJavier S. Pedro <maemo@javispedro.com>2013-04-07 04:19:54 +0200
committerJavier S. Pedro <maemo@javispedro.com>2013-04-07 04:19:54 +0200
commit0a3f6f27868a6eaa15d27cfe5be303292737b562 (patch)
treeeca52784e4ad518e3fbeaa0afb104878a1217496
parent564f185e62e85fbd1662e9da06abbd853bab7266 (diff)
downloadtapasboard-0a3f6f27868a6eaa15d27cfe5be303292737b562.tar.gz
tapasboard-0a3f6f27868a6eaa15d27cfe5be303292737b562.zip
add categories for forum view
-rw-r--r--board.cpp6
-rw-r--r--board.h4
-rw-r--r--forummodel.cpp14
-rw-r--r--forummodel.h2
-rw-r--r--qml/ForumPage.qml8
5 files changed, 31 insertions, 3 deletions
diff --git a/board.cpp b/board.cpp
index 26908b7..8f7c0cb 100644
--- a/board.cpp
+++ b/board.cpp
@@ -226,7 +226,7 @@ QString Board::parseSmilies(QString text) const
return text;
}
-QString Board::renderHumanDate(const QDateTime &dateTime)
+QString Board::renderHumanDate(const QDateTime &dateTime, bool monthOnly)
{
QDate date = dateTime.toLocalTime().date();
QDate today = QDate::currentDate();
@@ -236,6 +236,10 @@ QString Board::renderHumanDate(const QDateTime &dateTime)
return tr("Yesterday");
} else if (date.daysTo(today) < 5) {
return QDate::longDayName(date.dayOfWeek(), QDate::StandaloneFormat);
+ } else if (monthOnly && date.daysTo(today) < date.daysInYear()) {
+ return QDate::longMonthName(date.month(), QDate::StandaloneFormat);
+ } else if (monthOnly) {
+ return QString::number(date.year());
} else {
return date.toString(Qt::DefaultLocaleShortDate);
}
diff --git a/board.h b/board.h
index d7e91a2..c38bd48 100644
--- a/board.h
+++ b/board.h
@@ -68,8 +68,8 @@ public:
QString bbcodeToRichText(QString text) const;
QString parseSmilies(QString text) const;
- QString renderHumanDate(const QDateTime& dateTime);
- QString renderHumanDateTime(const QDateTime& dateTime);
+ Q_INVOKABLE QString renderHumanDate(const QDateTime& dateTime, bool monthOnly = false);
+ Q_INVOKABLE QString renderHumanDateTime(const QDateTime& dateTime);
public slots:
void cancelAllActions();
diff --git a/forummodel.cpp b/forummodel.cpp
index 14f053f..3e912c6 100644
--- a/forummodel.cpp
+++ b/forummodel.cpp
@@ -15,7 +15,10 @@ ForumModel::ForumModel(QObject *parent) :
roles[TitleRole] = QByteArray("title");
roles[IconRole] = QByteArray("icon");
roles[TopicIdRole] = QByteArray("topicId");
+ roles[TopicTypeRole] = QByteArray("topicType");
+ roles[LastReplyTimeRole] = QByteArray("lastReplyTime");
roles[NumRepliesRole] = QByteArray("numReplies");
+ roles[HumanDateRole] = QByteArray("humanDate");
roles[UnreadRole] = QByteArray("unread");
setRoleNames(roles);
}
@@ -89,8 +92,19 @@ QVariant ForumModel::data(const QModelIndex &index, int role) const
return _data[row].topic_id;
case TopicTypeRole:
return _data[row].type;
+ case LastReplyTimeRole:
+ return _data[row].last_reply_time;
case NumRepliesRole:
return _data[row].num_replies;
+ case HumanDateRole:
+ switch (_data[row].type) {
+ case Board::Announcement:
+ return tr("Announcement");
+ case Board::Sticky:
+ return tr("Sticky");
+ default:
+ return _board->renderHumanDate(_data[row].last_reply_time, true);
+ }
case UnreadRole:
return _data[row].unread;
}
diff --git a/forummodel.h b/forummodel.h
index 709f5c4..76f6912 100644
--- a/forummodel.h
+++ b/forummodel.h
@@ -22,7 +22,9 @@ public:
TopicIdRole = Qt::UserRole,
TopicTypeRole,
+ LastReplyTimeRole,
NumRepliesRole,
+ HumanDateRole,
UnreadRole
};
diff --git a/qml/ForumPage.qml b/qml/ForumPage.qml
index 6c21742..e2e263f 100644
--- a/qml/ForumPage.qml
+++ b/qml/ForumPage.qml
@@ -53,6 +53,14 @@ Page {
board: forumPage.board
forumId: forumPage.forumId
}
+
+ section.property: "humanDate"
+ section.criteria: ViewSection.FullString
+ section.delegate: GroupHeader {
+ width: parent.width
+ text: section
+ }
+
delegate: EmptyListDelegate {
id: topicItem