diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-01-11 14:58:20 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-01-11 14:58:20 +0100 |
commit | 7129af7b55dd13c8caa359f7cda9642bfab533b4 (patch) | |
tree | fefd73bb88f1c6600e0ec1c7a1f2c11f4b270a17 | |
parent | 41927399c33eae952f78b8361d145c00c5f744d2 (diff) | |
download | kube-7129af7b55dd13c8caa359f7cda9642bfab533b4.tar.gz kube-7129af7b55dd13c8caa359f7cda9642bfab533b4.zip |
Fetch incomplete mails automatically.
-rw-r--r-- | framework/domain/maillistmodel.cpp | 17 | ||||
-rw-r--r-- | framework/domain/maillistmodel.h | 4 |
2 files changed, 21 insertions, 0 deletions
diff --git a/framework/domain/maillistmodel.cpp b/framework/domain/maillistmodel.cpp index 0e76e0a8..207128b7 100644 --- a/framework/domain/maillistmodel.cpp +++ b/framework/domain/maillistmodel.cpp | |||
@@ -125,9 +125,23 @@ bool MailListModel::lessThan(const QModelIndex &left, const QModelIndex &right) | |||
125 | void MailListModel::runQuery(const Sink::Query &query) | 125 | void MailListModel::runQuery(const Sink::Query &query) |
126 | { | 126 | { |
127 | m_model = Sink::Store::loadModel<Sink::ApplicationDomain::Mail>(query); | 127 | m_model = Sink::Store::loadModel<Sink::ApplicationDomain::Mail>(query); |
128 | QObject::connect(m_model.data(), &QAbstractItemModel::rowsInserted, this, &MailListModel::onRowsInserted); | ||
128 | setSourceModel(m_model.data()); | 129 | setSourceModel(m_model.data()); |
129 | } | 130 | } |
130 | 131 | ||
132 | void MailListModel::onRowsInserted(const QModelIndex &parent, int begin, int end) | ||
133 | { | ||
134 | if (mFetchMails) { | ||
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 | |||
131 | void MailListModel::setParentFolder(const QVariant &parentFolder) | 145 | void MailListModel::setParentFolder(const QVariant &parentFolder) |
132 | { | 146 | { |
133 | using namespace Sink::ApplicationDomain; | 147 | using namespace Sink::ApplicationDomain; |
@@ -150,6 +164,7 @@ void MailListModel::setParentFolder(const QVariant &parentFolder) | |||
150 | query.request<Mail::Draft>(); | 164 | query.request<Mail::Draft>(); |
151 | query.request<Mail::Trash>(); | 165 | query.request<Mail::Trash>(); |
152 | query.request<Mail::Folder>(); | 166 | query.request<Mail::Folder>(); |
167 | mFetchMails = false; | ||
153 | qWarning() << "Running folder query: " << folder->resourceInstanceIdentifier() << folder->identifier(); | 168 | qWarning() << "Running folder query: " << folder->resourceInstanceIdentifier() << folder->identifier(); |
154 | runQuery(query); | 169 | runQuery(query); |
155 | } | 170 | } |
@@ -179,6 +194,8 @@ void MailListModel::setMail(const QVariant &variant) | |||
179 | query.request<Mail::Draft>(); | 194 | query.request<Mail::Draft>(); |
180 | query.request<Mail::Trash>(); | 195 | query.request<Mail::Trash>(); |
181 | query.request<Mail::MimeMessage>(); | 196 | query.request<Mail::MimeMessage>(); |
197 | query.request<Mail::FullPayloadAvailable>(); | ||
198 | mFetchMails = true; | ||
182 | qWarning() << "Running mail query: " << mail->resourceInstanceIdentifier() << mail->identifier(); | 199 | qWarning() << "Running mail query: " << mail->resourceInstanceIdentifier() << mail->identifier(); |
183 | runQuery(query); | 200 | runQuery(query); |
184 | } | 201 | } |
diff --git a/framework/domain/maillistmodel.h b/framework/domain/maillistmodel.h index 71a0a6df..faed9edf 100644 --- a/framework/domain/maillistmodel.h +++ b/framework/domain/maillistmodel.h | |||
@@ -68,6 +68,10 @@ 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 | private: | 74 | private: |
72 | QSharedPointer<QAbstractItemModel> m_model; | 75 | QSharedPointer<QAbstractItemModel> m_model; |
76 | bool mFetchMails = false; | ||
73 | }; | 77 | }; |