summaryrefslogtreecommitdiffstats
path: root/framework/domain
diff options
context:
space:
mode:
authorSandro Knauß <sknauss@kde.org>2016-10-11 16:19:01 +0200
committerSandro Knauß <sknauss@kde.org>2016-10-11 16:19:01 +0200
commit7d6ec8866c90918be94364e52bbdd4f3e53da915 (patch)
tree007cc6ded7358a7dcdf8a5a87202bb5378f60d93 /framework/domain
parent1974c19eadd497e355ac985a00d0571f3e6c7712 (diff)
parentfd3a6901f17f3dcfd446e531dd10c0eb61cf0b93 (diff)
downloadkube-7d6ec8866c90918be94364e52bbdd4f3e53da915.tar.gz
kube-7d6ec8866c90918be94364e52bbdd4f3e53da915.zip
Merge branch 'develop' into dev/mimetreeinterface
Diffstat (limited to 'framework/domain')
-rw-r--r--framework/domain/CMakeLists.txt1
-rw-r--r--framework/domain/maillistmodel.cpp18
-rw-r--r--framework/domain/maillistmodel.h5
-rw-r--r--framework/domain/mailplugin.cpp2
-rw-r--r--framework/domain/outboxmodel.cpp114
-rw-r--r--framework/domain/outboxmodel.h60
6 files changed, 189 insertions, 11 deletions
diff --git a/framework/domain/CMakeLists.txt b/framework/domain/CMakeLists.txt
index c41da377..55bc2f24 100644
--- a/framework/domain/CMakeLists.txt
+++ b/framework/domain/CMakeLists.txt
@@ -14,6 +14,7 @@ set(mailplugin_SRCS
14 accountfactory.cpp 14 accountfactory.cpp
15 accountscontroller.cpp 15 accountscontroller.cpp
16 accountsmodel.cpp 16 accountsmodel.cpp
17 outboxmodel.cpp
17 identitiesmodel.cpp 18 identitiesmodel.cpp
18 settings/accountsettings.cpp 19 settings/accountsettings.cpp
19) 20)
diff --git a/framework/domain/maillistmodel.cpp b/framework/domain/maillistmodel.cpp
index 9afb6408..746f3523 100644
--- a/framework/domain/maillistmodel.cpp
+++ b/framework/domain/maillistmodel.cpp
@@ -23,6 +23,7 @@
23#include <QFile> 23#include <QFile>
24#include <QDateTime> 24#include <QDateTime>
25 25
26#include <sink/standardqueries.h>
26 27
27MailListModel::MailListModel(QObject *parent) 28MailListModel::MailListModel(QObject *parent)
28 : QSortFilterProxyModel() 29 : QSortFilterProxyModel()
@@ -50,6 +51,7 @@ QHash< int, QByteArray > MailListModel::roleNames() const
50 roles[Id] = "id"; 51 roles[Id] = "id";
51 roles[MimeMessage] = "mimeMessage"; 52 roles[MimeMessage] = "mimeMessage";
52 roles[DomainObject] = "domainObject"; 53 roles[DomainObject] = "domainObject";
54 roles[ThreadSize] = "threadSize";
53 55
54 return roles; 56 return roles;
55} 57}
@@ -68,18 +70,19 @@ QVariant MailListModel::data(const QModelIndex &idx, int role) const
68 case Date: 70 case Date:
69 return mail->getDate(); 71 return mail->getDate();
70 case Unread: 72 case Unread:
71 return mail->getUnread(); 73 return mail->getProperty("unreadCollected").toList().contains(true);
72 case Important: 74 case Important:
73 return mail->getImportant(); 75 return mail->getProperty("importantCollected").toList().contains(true);
74 case Draft: 76 case Draft:
75 return mail->getDraft(); 77 return mail->getDraft();
76 case Id: 78 case Id:
77 return mail->identifier(); 79 return mail->identifier();
78 case DomainObject: 80 case DomainObject:
79 return QVariant::fromValue(mail); 81 return QVariant::fromValue(mail);
80 case MimeMessage: { 82 case MimeMessage:
81 return mail->getMimeMessage(); 83 return mail->getMimeMessage();
82 } 84 case ThreadSize:
85 return mail->getProperty("count").toInt();
83 } 86 }
84 return QSortFilterProxyModel::data(idx, role); 87 return QSortFilterProxyModel::data(idx, role);
85} 88}
@@ -105,10 +108,8 @@ void MailListModel::setParentFolder(const QVariant &parentFolder)
105 qWarning() << "No folder: " << parentFolder; 108 qWarning() << "No folder: " << parentFolder;
106 return; 109 return;
107 } 110 }
108 Sink::Query query; 111 Sink::Query query = Sink::StandardQueries::threadLeaders(*folder);
109 query.liveQuery = true; 112 query.liveQuery = true;
110 query.resourceFilter(folder->resourceInstanceIdentifier());
111 query.sort<Mail::Date>();
112 query.limit = 100; 113 query.limit = 100;
113 query.request<Mail::Subject>(); 114 query.request<Mail::Subject>();
114 query.request<Mail::Sender>(); 115 query.request<Mail::Sender>();
@@ -118,7 +119,6 @@ void MailListModel::setParentFolder(const QVariant &parentFolder)
118 query.request<Mail::Important>(); 119 query.request<Mail::Important>();
119 query.request<Mail::Draft>(); 120 query.request<Mail::Draft>();
120 query.request<Mail::Folder>(); 121 query.request<Mail::Folder>();
121 query.filter<Mail::Folder>(*folder);
122 qWarning() << "Running folder query: " << folder->resourceInstanceIdentifier() << folder->identifier(); 122 qWarning() << "Running folder query: " << folder->resourceInstanceIdentifier() << folder->identifier();
123 runQuery(query); 123 runQuery(query);
124} 124}
@@ -136,7 +136,7 @@ void MailListModel::setMail(const QVariant &variant)
136 qWarning() << "No mail: " << mail; 136 qWarning() << "No mail: " << mail;
137 return; 137 return;
138 } 138 }
139 Sink::Query query(*mail); 139 Sink::Query query = Sink::StandardQueries::completeThread(*mail);
140 query.liveQuery = false; 140 query.liveQuery = false;
141 query.request<Mail::Subject>(); 141 query.request<Mail::Subject>();
142 query.request<Mail::Sender>(); 142 query.request<Mail::Sender>();
diff --git a/framework/domain/maillistmodel.h b/framework/domain/maillistmodel.h
index 13662a17..a7cb5d84 100644
--- a/framework/domain/maillistmodel.h
+++ b/framework/domain/maillistmodel.h
@@ -50,10 +50,11 @@ public:
50 Draft, 50 Draft,
51 Id, 51 Id,
52 MimeMessage, 52 MimeMessage,
53 DomainObject 53 DomainObject,
54 ThreadSize
54 }; 55 };
55 56
56 QHash<int, QByteArray> roleNames() const; 57 QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;
57 58
58 void runQuery(const Sink::Query &query); 59 void runQuery(const Sink::Query &query);
59 60
diff --git a/framework/domain/mailplugin.cpp b/framework/domain/mailplugin.cpp
index 9f06fd5f..c7023bde 100644
--- a/framework/domain/mailplugin.cpp
+++ b/framework/domain/mailplugin.cpp
@@ -28,6 +28,7 @@
28#include "accountfactory.h" 28#include "accountfactory.h"
29#include "accountscontroller.h" 29#include "accountscontroller.h"
30#include "accountsmodel.h" 30#include "accountsmodel.h"
31#include "outboxmodel.h"
31 32
32#include <QtQml> 33#include <QtQml>
33 34
@@ -43,4 +44,5 @@ void MailPlugin::registerTypes (const char *uri)
43 qmlRegisterType<AccountFactory>(uri, 1, 0, "AccountFactory"); 44 qmlRegisterType<AccountFactory>(uri, 1, 0, "AccountFactory");
44 qmlRegisterType<AccountsController>(uri, 1, 0, "AccountsController"); 45 qmlRegisterType<AccountsController>(uri, 1, 0, "AccountsController");
45 qmlRegisterType<AccountsModel>(uri, 1, 0, "AccountsModel"); 46 qmlRegisterType<AccountsModel>(uri, 1, 0, "AccountsModel");
47 qmlRegisterType<OutboxModel>(uri, 1, 0, "OutboxModel");
46} 48}
diff --git a/framework/domain/outboxmodel.cpp b/framework/domain/outboxmodel.cpp
new file mode 100644
index 00000000..b3533976
--- /dev/null
+++ b/framework/domain/outboxmodel.cpp
@@ -0,0 +1,114 @@
1/*
2 Copyright (c) 2016 Michael Bohlender <michael.bohlender@kdemail.net>
3 Copyright (c) 2016 Christian Mollekopf <mollekopf@kolabsys.com>
4
5 This library is free software; you can redistribute it and/or modify it
6 under the terms of the GNU Library General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or (at your
8 option) any later version.
9
10 This library is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 02110-1301, USA.
19*/
20
21#include "outboxmodel.h"
22
23#include <QFile>
24#include <QDateTime>
25
26#include <sink/standardqueries.h>
27
28
29OutboxModel::OutboxModel(QObject *parent)
30 : QSortFilterProxyModel()
31{
32 setDynamicSortFilter(true);
33 sort(0, Qt::DescendingOrder);
34
35 using namespace Sink::ApplicationDomain;
36 auto query = Sink::StandardQueries::outboxMails();
37 query.liveQuery = true;
38 query.request<Mail::Subject>();
39 query.request<Mail::Sender>();
40 query.request<Mail::SenderName>();
41 query.request<Mail::Date>();
42 query.request<Mail::Unread>();
43 query.request<Mail::Important>();
44 query.request<Mail::Draft>();
45 query.request<Mail::Folder>();
46 runQuery(query);
47}
48
49OutboxModel::~OutboxModel()
50{
51
52}
53
54QHash< int, QByteArray > OutboxModel::roleNames() const
55{
56 QHash<int, QByteArray> roles;
57
58 roles[Subject] = "subject";
59 roles[Sender] = "sender";
60 roles[SenderName] = "senderName";
61 roles[Date] = "date";
62 roles[Unread] = "unread";
63 roles[Important] = "important";
64 roles[Draft] = "draft";
65 roles[Id] = "id";
66 roles[MimeMessage] = "mimeMessage";
67 roles[DomainObject] = "domainObject";
68
69 return roles;
70}
71
72QVariant OutboxModel::data(const QModelIndex &idx, int role) const
73{
74 auto srcIdx = mapToSource(idx);
75 auto mail = srcIdx.data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Mail::Ptr>();
76 switch (role) {
77 case Subject:
78 return mail->getSubject();
79 case Sender:
80 return mail->getSender();
81 case SenderName:
82 return mail->getSenderName();
83 case Date:
84 return mail->getDate();
85 case Unread:
86 return mail->getUnread();
87 case Important:
88 return mail->getImportant();
89 case Draft:
90 return mail->getDraft();
91 case Id:
92 return mail->identifier();
93 case DomainObject:
94 return QVariant::fromValue(mail);
95 case MimeMessage: {
96 return mail->getMimeMessage();
97 }
98 }
99 return QSortFilterProxyModel::data(idx, role);
100}
101
102bool OutboxModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
103{
104 const auto leftDate = left.data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Mail::Ptr>()->getDate();
105 const auto rightDate = right.data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Mail::Ptr>()->getDate();
106 return leftDate < rightDate;
107}
108
109void OutboxModel::runQuery(const Sink::Query &query)
110{
111 m_model = Sink::Store::loadModel<Sink::ApplicationDomain::Mail>(query);
112 setSourceModel(m_model.data());
113}
114
diff --git a/framework/domain/outboxmodel.h b/framework/domain/outboxmodel.h
new file mode 100644
index 00000000..d2fa17ac
--- /dev/null
+++ b/framework/domain/outboxmodel.h
@@ -0,0 +1,60 @@
1/*
2 Copyright (c) 2016 Michael Bohlender <michael.bohlender@kdemail.net>
3 Copyright (c) 2016 Christian Mollekopf <mollekopf@kolabsys.com>
4
5 This library is free software; you can redistribute it and/or modify it
6 under the terms of the GNU Library General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or (at your
8 option) any later version.
9
10 This library is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 02110-1301, USA.
19*/
20
21#pragma once
22
23#include <sink/store.h>
24
25#include <QSortFilterProxyModel>
26#include <QSharedPointer>
27#include <QStringList>
28
29class OutboxModel : public QSortFilterProxyModel
30{
31 Q_OBJECT
32
33public:
34 OutboxModel(QObject *parent = Q_NULLPTR);
35 ~OutboxModel();
36
37 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
38
39 bool lessThan(const QModelIndex &left, const QModelIndex &right) const Q_DECL_OVERRIDE;
40
41 enum Roles {
42 Subject = Qt::UserRole + 1,
43 Sender,
44 SenderName,
45 Date,
46 Unread,
47 Important,
48 Draft,
49 Id,
50 MimeMessage,
51 DomainObject
52 };
53
54 QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;
55
56 void runQuery(const Sink::Query &query);
57
58private:
59 QSharedPointer<QAbstractItemModel> m_model;
60};