summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-10-10 16:34:48 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-10-10 16:34:48 +0200
commit91f00fe588c9f00ac92f2d095c6ee9dd74c007a0 (patch)
tree147dda91a1df830cdffe2a2a8b79ba39bf8d6386
parent9f89215be2612dbf54ad50c42565c310e3f4099c (diff)
downloadkube-91f00fe588c9f00ac92f2d095c6ee9dd74c007a0.tar.gz
kube-91f00fe588c9f00ac92f2d095c6ee9dd74c007a0.zip
An outbox model
-rw-r--r--components/package/contents/ui/Outbox.qml7
-rw-r--r--framework/domain/CMakeLists.txt1
-rw-r--r--framework/domain/mailplugin.cpp2
-rw-r--r--framework/domain/outboxmodel.cpp114
-rw-r--r--framework/domain/outboxmodel.h60
5 files changed, 181 insertions, 3 deletions
diff --git a/components/package/contents/ui/Outbox.qml b/components/package/contents/ui/Outbox.qml
index 01501410..c7b1f7b0 100644
--- a/components/package/contents/ui/Outbox.qml
+++ b/components/package/contents/ui/Outbox.qml
@@ -39,7 +39,7 @@ ToolButton {
39 Rectangle { 39 Rectangle {
40 id: dialog 40 id: dialog
41 41
42 property int modelCount: 5 //FIXME replace with actual model 42 property int modelCount: listView.count
43 43
44 anchors { 44 anchors {
45 top: parent.bottom 45 top: parent.bottom
@@ -68,7 +68,8 @@ ToolButton {
68 ListView { 68 ListView {
69 id: listView 69 id: listView
70 70
71 model: 5 71 model: KubeFramework.OutboxModel {
72 }
72 73
73 delegate: Kirigami.AbstractListItem { 74 delegate: Kirigami.AbstractListItem {
74 75
@@ -76,7 +77,7 @@ ToolButton {
76 77
77 Kirigami.Label { 78 Kirigami.Label {
78 anchors.centerIn: parent 79 anchors.centerIn: parent
79 text: "Subjext subxetson" 80 text: model.subject
80 } 81 }
81 } 82 }
82 } 83 }
diff --git a/framework/domain/CMakeLists.txt b/framework/domain/CMakeLists.txt
index ea293655..804b3ccb 100644
--- a/framework/domain/CMakeLists.txt
+++ b/framework/domain/CMakeLists.txt
@@ -12,6 +12,7 @@ set(mailplugin_SRCS
12 accountfactory.cpp 12 accountfactory.cpp
13 accountscontroller.cpp 13 accountscontroller.cpp
14 accountsmodel.cpp 14 accountsmodel.cpp
15 outboxmodel.cpp
15 identitiesmodel.cpp 16 identitiesmodel.cpp
16 settings/accountsettings.cpp 17 settings/accountsettings.cpp
17) 18)
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};