diff options
Diffstat (limited to 'framework/src')
-rw-r--r-- | framework/src/domain/folderlistmodel.cpp | 41 | ||||
-rw-r--r-- | framework/src/domain/folderlistmodel.h | 8 | ||||
-rw-r--r-- | framework/src/sinkfabric.cpp | 5 |
3 files changed, 53 insertions, 1 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(); |
diff --git a/framework/src/domain/folderlistmodel.h b/framework/src/domain/folderlistmodel.h index 738cf4a0..d3bef397 100644 --- a/framework/src/domain/folderlistmodel.h +++ b/framework/src/domain/folderlistmodel.h | |||
@@ -22,6 +22,8 @@ | |||
22 | 22 | ||
23 | #include <krecursivefilterproxymodel.h> | 23 | #include <krecursivefilterproxymodel.h> |
24 | #include <QSharedPointer> | 24 | #include <QSharedPointer> |
25 | #include <QSet> | ||
26 | #include <sink/notifier.h> | ||
25 | 27 | ||
26 | namespace Sink { | 28 | namespace Sink { |
27 | class Query; | 29 | class Query; |
@@ -54,7 +56,8 @@ public: | |||
54 | Id, | 56 | Id, |
55 | DomainObject, | 57 | DomainObject, |
56 | Status, | 58 | Status, |
57 | Trash | 59 | Trash, |
60 | HasNewData | ||
58 | }; | 61 | }; |
59 | Q_ENUMS(Roles) | 62 | Q_ENUMS(Roles) |
60 | 63 | ||
@@ -68,8 +71,11 @@ public: | |||
68 | protected: | 71 | protected: |
69 | bool lessThan(const QModelIndex &left, const QModelIndex &right) const Q_DECL_OVERRIDE; | 72 | bool lessThan(const QModelIndex &left, const QModelIndex &right) const Q_DECL_OVERRIDE; |
70 | bool acceptRow(int sourceRow, const QModelIndex &sourceParent) const Q_DECL_OVERRIDE; | 73 | bool acceptRow(int sourceRow, const QModelIndex &sourceParent) const Q_DECL_OVERRIDE; |
74 | void fetchMore(const QModelIndex &left) Q_DECL_OVERRIDE; | ||
71 | 75 | ||
72 | private: | 76 | private: |
73 | void runQuery(const Sink::Query &query); | 77 | void runQuery(const Sink::Query &query); |
74 | QSharedPointer<QAbstractItemModel> mModel; | 78 | QSharedPointer<QAbstractItemModel> mModel; |
79 | QSet<QByteArray> mHasNewData; | ||
80 | QScopedPointer<Sink::Notifier> mNotifier; | ||
75 | }; | 81 | }; |
diff --git a/framework/src/sinkfabric.cpp b/framework/src/sinkfabric.cpp index 8492f272..916cc8fa 100644 --- a/framework/src/sinkfabric.cpp +++ b/framework/src/sinkfabric.cpp | |||
@@ -203,6 +203,11 @@ public: | |||
203 | if (notification.code == Sink::ApplicationDomain::TransmissionSuccess) { | 203 | if (notification.code == Sink::ApplicationDomain::TransmissionSuccess) { |
204 | message["type"] = "info"; | 204 | message["type"] = "info"; |
205 | message["message"] = QObject::tr("A message has been sent."); | 205 | message["message"] = QObject::tr("A message has been sent."); |
206 | } else if (notification.code == Sink::ApplicationDomain::NewContentAvailable) { | ||
207 | message["type"] = "info"; | ||
208 | if (!notification.entities.isEmpty()) { | ||
209 | message["folderId"] = notification.entities.first(); | ||
210 | } | ||
206 | } else { | 211 | } else { |
207 | return; | 212 | return; |
208 | } | 213 | } |