diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-02-08 23:40:49 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-02-08 23:41:07 +0100 |
commit | 9f548500214925cd0075fd2434afd116618d7196 (patch) | |
tree | df3cc604a2a602f61a66548eb5c5bfb3e62aa55d /framework/domain | |
parent | 7c291e282099d90cd87caab2ad610710ae28523d (diff) | |
download | kube-9f548500214925cd0075fd2434afd116618d7196.tar.gz kube-9f548500214925cd0075fd2434afd116618d7196.zip |
Fetch the mail when trying to access the content.
That way we can try to only fetch the content for messages that are
actually shown.
Diffstat (limited to 'framework/domain')
-rw-r--r-- | framework/domain/maillistmodel.cpp | 25 | ||||
-rw-r--r-- | framework/domain/maillistmodel.h | 2 |
2 files changed, 11 insertions, 16 deletions
diff --git a/framework/domain/maillistmodel.cpp b/framework/domain/maillistmodel.cpp index c33d8b67..6fe80092 100644 --- a/framework/domain/maillistmodel.cpp +++ b/framework/domain/maillistmodel.cpp | |||
@@ -74,6 +74,14 @@ static QString join(const QList<Sink::ApplicationDomain::Mail::Contact> &contact | |||
74 | return list.join(", "); | 74 | return list.join(", "); |
75 | } | 75 | } |
76 | 76 | ||
77 | void fetchMail(Sink::ApplicationDomain::Mail::Ptr mail) | ||
78 | { | ||
79 | if (mail && !mail->getFullPayloadAvailable()) { | ||
80 | qWarning() << "Fetching mail: " << mail->identifier() << mail->getSubject(); | ||
81 | Sink::Store::synchronize(Sink::SyncScope{*mail}).exec(); | ||
82 | } | ||
83 | } | ||
84 | |||
77 | QVariant MailListModel::data(const QModelIndex &idx, int role) const | 85 | QVariant MailListModel::data(const QModelIndex &idx, int role) const |
78 | { | 86 | { |
79 | auto srcIdx = mapToSource(idx); | 87 | auto srcIdx = mapToSource(idx); |
@@ -106,6 +114,9 @@ QVariant MailListModel::data(const QModelIndex &idx, int role) const | |||
106 | case DomainObject: | 114 | case DomainObject: |
107 | return QVariant::fromValue(mail); | 115 | return QVariant::fromValue(mail); |
108 | case MimeMessage: | 116 | case MimeMessage: |
117 | if (mFetchMails) { | ||
118 | fetchMail(mail); | ||
119 | } | ||
109 | return mail->getMimeMessage(); | 120 | return mail->getMimeMessage(); |
110 | case ThreadSize: | 121 | case ThreadSize: |
111 | return mail->getProperty("count").toInt(); | 122 | return mail->getProperty("count").toInt(); |
@@ -125,23 +136,9 @@ bool MailListModel::lessThan(const QModelIndex &left, const QModelIndex &right) | |||
125 | void MailListModel::runQuery(const Sink::Query &query) | 136 | void MailListModel::runQuery(const Sink::Query &query) |
126 | { | 137 | { |
127 | m_model = Sink::Store::loadModel<Sink::ApplicationDomain::Mail>(query); | 138 | m_model = Sink::Store::loadModel<Sink::ApplicationDomain::Mail>(query); |
128 | QObject::connect(m_model.data(), &QAbstractItemModel::rowsInserted, this, &MailListModel::onRowsInserted); | ||
129 | setSourceModel(m_model.data()); | 139 | setSourceModel(m_model.data()); |
130 | } | 140 | } |
131 | 141 | ||
132 | void MailListModel::onRowsInserted(const QModelIndex &parent, int begin, int end) | ||
133 | { | ||
134 | if (mFetchMails && sourceModel()) { | ||
135 | for (int row = begin; row <= end; row++) { | ||
136 | auto mail = sourceModel()->index(row, 0, parent).data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Mail::Ptr>(); | ||
137 | if (mail && !mail->getFullPayloadAvailable()) { | ||
138 | qWarning() << "Fetching mail: " << mail->identifier(); | ||
139 | Sink::Store::synchronize(Sink::SyncScope{*mail}).exec(); | ||
140 | } | ||
141 | } | ||
142 | } | ||
143 | } | ||
144 | |||
145 | void MailListModel::setParentFolder(const QVariant &parentFolder) | 142 | void MailListModel::setParentFolder(const QVariant &parentFolder) |
146 | { | 143 | { |
147 | using namespace Sink::ApplicationDomain; | 144 | using namespace Sink::ApplicationDomain; |
diff --git a/framework/domain/maillistmodel.h b/framework/domain/maillistmodel.h index faed9edf..dbb24a4d 100644 --- a/framework/domain/maillistmodel.h +++ b/framework/domain/maillistmodel.h | |||
@@ -68,8 +68,6 @@ public: | |||
68 | 68 | ||
69 | void setMail(const QVariant &mail); | 69 | void setMail(const QVariant &mail); |
70 | QVariant mail() const; | 70 | QVariant mail() const; |
71 | private slots: | ||
72 | void onRowsInserted(const QModelIndex &idx, int, int); | ||
73 | 71 | ||
74 | private: | 72 | private: |
75 | QSharedPointer<QAbstractItemModel> m_model; | 73 | QSharedPointer<QAbstractItemModel> m_model; |