diff options
Diffstat (limited to 'framework/src/domain/folderlistmodel.cpp')
-rw-r--r-- | framework/src/domain/folderlistmodel.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/framework/src/domain/folderlistmodel.cpp b/framework/src/domain/folderlistmodel.cpp index f929b01e..6555abbf 100644 --- a/framework/src/domain/folderlistmodel.cpp +++ b/framework/src/domain/folderlistmodel.cpp | |||
@@ -21,6 +21,8 @@ | |||
21 | #include "folderlistmodel.h" | 21 | #include "folderlistmodel.h" |
22 | #include <sink/store.h> | 22 | #include <sink/store.h> |
23 | #include <sink/log.h> | 23 | #include <sink/log.h> |
24 | #include <sink/notifier.h> | ||
25 | #include <sink/notification.h> | ||
24 | #include <settings/settings.h> | 26 | #include <settings/settings.h> |
25 | 27 | ||
26 | using namespace Sink; | 28 | using namespace Sink; |
@@ -59,6 +61,7 @@ QHash< int, QByteArray > FolderListModel::roleNames() const | |||
59 | roles[DomainObject] = "domainObject"; | 61 | roles[DomainObject] = "domainObject"; |
60 | roles[Status] = "status"; | 62 | roles[Status] = "status"; |
61 | roles[Trash] = "trash"; | 63 | roles[Trash] = "trash"; |
64 | roles[HasNewData] = "hasNewData"; | ||
62 | 65 | ||
63 | return roles; | 66 | return roles; |
64 | } | 67 | } |
@@ -92,14 +95,46 @@ QVariant FolderListModel::data(const QModelIndex &idx, int role) const | |||
92 | return folder->getSpecialPurpose().contains(Sink::ApplicationDomain::SpecialPurpose::Mail::trash); | 95 | return folder->getSpecialPurpose().contains(Sink::ApplicationDomain::SpecialPurpose::Mail::trash); |
93 | } | 96 | } |
94 | return false; | 97 | return false; |
98 | case HasNewData: | ||
99 | return mHasNewData.contains(folder->identifier()); | ||
95 | } | 100 | } |
96 | return QSortFilterProxyModel::data(idx, role); | 101 | return QSortFilterProxyModel::data(idx, role); |
97 | } | 102 | } |
98 | 103 | ||
104 | static QModelIndex findRecursive(QAbstractItemModel *model, const QModelIndex &parent, int role, const QVariant &value) | ||
105 | { | ||
106 | for (auto row = 0; row < model->rowCount(parent); row++) { | ||
107 | const auto idx = model->index(row, 0, parent); | ||
108 | if (model->data(idx, role) == value) { | ||
109 | return idx; | ||
110 | } | ||
111 | auto result = findRecursive(model, idx, role, value); | ||
112 | if (result.isValid()) { | ||
113 | return result; | ||
114 | } | ||
115 | } | ||
116 | return {}; | ||
117 | } | ||
118 | |||
99 | void FolderListModel::runQuery(const Query &query) | 119 | void FolderListModel::runQuery(const Query &query) |
100 | { | 120 | { |
101 | mModel = Store::loadModel<Folder>(query); | 121 | mModel = Store::loadModel<Folder>(query); |
102 | setSourceModel(mModel.data()); | 122 | setSourceModel(mModel.data()); |
123 | |||
124 | Sink::Query resourceQuery; | ||
125 | resourceQuery.setFilter(query.getResourceFilter()); | ||
126 | mNotifier.reset(new Sink::Notifier{resourceQuery}); | ||
127 | mNotifier->registerHandler([&](const Sink::Notification ¬ification) { | ||
128 | if (notification.type == Sink::Notification::Info && notification.code == ApplicationDomain::NewContentAvailable) { | ||
129 | if (!notification.entities.isEmpty()) { | ||
130 | mHasNewData.insert(notification.entities.first()); | ||
131 | auto idx = findRecursive(this, {}, Id, QVariant::fromValue(notification.entities.first())); | ||
132 | if (idx.isValid()) { | ||
133 | emit dataChanged(idx, idx); | ||
134 | } | ||
135 | } | ||
136 | } | ||
137 | }); | ||
103 | } | 138 | } |
104 | 139 | ||
105 | void FolderListModel::setAccountId(const QVariant &accountId) | 140 | void FolderListModel::setAccountId(const QVariant &accountId) |
@@ -164,6 +199,12 @@ bool FolderListModel::acceptRow(int sourceRow, const QModelIndex &sourceParent) | |||
164 | return enabled; | 199 | return enabled; |
165 | } | 200 | } |
166 | 201 | ||
202 | void FolderListModel::fetchMore(const QModelIndex &parent) | ||
203 | { | ||
204 | mHasNewData.remove(parent.data(Id).toByteArray()); | ||
205 | QAbstractItemModel::fetchMore(parent); | ||
206 | } | ||
207 | |||
167 | void FolderListModel::setFolderId(const QVariant &folderId) | 208 | void FolderListModel::setFolderId(const QVariant &folderId) |
168 | { | 209 | { |
169 | const auto folder = folderId.toString().toUtf8(); | 210 | const auto folder = folderId.toString().toUtf8(); |