diff options
Diffstat (limited to 'framework/domain/maillistmodel.cpp')
-rw-r--r-- | framework/domain/maillistmodel.cpp | 25 |
1 files changed, 11 insertions, 14 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; |