summaryrefslogtreecommitdiffstats
path: root/framework/mail/maillistmodel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'framework/mail/maillistmodel.cpp')
-rw-r--r--framework/mail/maillistmodel.cpp73
1 files changed, 73 insertions, 0 deletions
diff --git a/framework/mail/maillistmodel.cpp b/framework/mail/maillistmodel.cpp
new file mode 100644
index 00000000..14219ee2
--- /dev/null
+++ b/framework/mail/maillistmodel.cpp
@@ -0,0 +1,73 @@
1#include "maillistmodel.h"
2
3#include <QDateTime>
4
5MailListModel::MailListModel(QObject *parent) : QAbstractListModel(parent), m_msgs()
6{
7
8}
9
10MailListModel::~MailListModel()
11{
12
13}
14
15QHash< int, QByteArray > MailListModel::roleNames() const
16{
17 QHash<int, QByteArray> roles;
18
19 roles[Subject] = "subject";
20
21 return roles;
22}
23
24
25QVariant MailListModel::data(const QModelIndex &index, int role) const
26{
27 if (!index.isValid()) {
28 return QVariant();
29 }
30
31 if (index.row() >= m_msgs.count() || index.row() < 0) {
32 return QVariant();
33 }
34 switch (role) {
35 case Subject:
36 return m_msgs.at(index.row());
37 }
38 return QVariant();
39}
40
41int MailListModel::rowCount(const QModelIndex &parent) const
42{
43 return m_msgs.size();
44}
45
46bool MailListModel::addMails(const QStringList &items)
47{
48 beginInsertRows(QModelIndex(), rowCount(), rowCount() + items.size() - 1);
49
50 m_msgs += items;
51
52 endInsertRows();
53
54 return true;
55}
56
57void MailListModel::clearMails()
58{
59 if (!m_msgs.isEmpty()) {
60 beginResetModel();
61 m_msgs.clear();
62 endResetModel();
63 }
64}
65
66void MailListModel::runQuery(const QString& query)
67{
68 clearMails();
69 QStringList itemlist;
70 itemlist << "I feel tiny" << "Big News!" << "[FUN] lets do things";
71 addMails(itemlist);
72}
73