diff options
Diffstat (limited to 'framework/mail/maillistmodel.cpp')
-rw-r--r-- | framework/mail/maillistmodel.cpp | 55 |
1 files changed, 10 insertions, 45 deletions
diff --git a/framework/mail/maillistmodel.cpp b/framework/mail/maillistmodel.cpp index 14219ee2..f18861c4 100644 --- a/framework/mail/maillistmodel.cpp +++ b/framework/mail/maillistmodel.cpp | |||
@@ -1,10 +1,12 @@ | |||
1 | #include "maillistmodel.h" | 1 | #include "maillistmodel.h" |
2 | 2 | ||
3 | #include <QDateTime> | 3 | MailListModel::MailListModel(QObject *parent) : ListModelResult<Akonadi2::ApplicationDomain::Mail::Ptr>(QList<QByteArray>() << "subject" << "uid") |
4 | |||
5 | MailListModel::MailListModel(QObject *parent) : QAbstractListModel(parent), m_msgs() | ||
6 | { | 4 | { |
7 | 5 | Akonadi2::Query query; | |
6 | query.syncOnDemand = false; | ||
7 | query.processAll = false; | ||
8 | query.liveQuery = true; | ||
9 | setEmitter(Akonadi2::Store::load<Akonadi2::ApplicationDomain::Mail>(query)); | ||
8 | } | 10 | } |
9 | 11 | ||
10 | MailListModel::~MailListModel() | 12 | MailListModel::~MailListModel() |
@@ -21,53 +23,16 @@ QHash< int, QByteArray > MailListModel::roleNames() const | |||
21 | return roles; | 23 | return roles; |
22 | } | 24 | } |
23 | 25 | ||
24 | 26 | QVariant MailListModel::data(const QModelIndex &idx, int role) const | |
25 | QVariant MailListModel::data(const QModelIndex &index, int role) const | ||
26 | { | 27 | { |
27 | if (!index.isValid()) { | 28 | switch (role) { |
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: | 29 | case Subject: |
36 | return m_msgs.at(index.row()); | 30 | return ListModelResult<Akonadi2::ApplicationDomain::Mail::Ptr>::data(index(idx.row(), 0, idx.parent()), Qt::DisplayRole); |
37 | } | ||
38 | return QVariant(); | ||
39 | } | ||
40 | |||
41 | int MailListModel::rowCount(const QModelIndex &parent) const | ||
42 | { | ||
43 | return m_msgs.size(); | ||
44 | } | ||
45 | |||
46 | bool 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 | |||
57 | void MailListModel::clearMails() | ||
58 | { | ||
59 | if (!m_msgs.isEmpty()) { | ||
60 | beginResetModel(); | ||
61 | m_msgs.clear(); | ||
62 | endResetModel(); | ||
63 | } | 31 | } |
32 | return QVariant(); | ||
64 | } | 33 | } |
65 | 34 | ||
66 | void MailListModel::runQuery(const QString& query) | 35 | void MailListModel::runQuery(const QString& query) |
67 | { | 36 | { |
68 | clearMails(); | ||
69 | QStringList itemlist; | ||
70 | itemlist << "I feel tiny" << "Big News!" << "[FUN] lets do things"; | ||
71 | addMails(itemlist); | ||
72 | } | 37 | } |
73 | 38 | ||