diff options
-rw-r--r-- | components/package/contents/ui/People.qml | 35 | ||||
-rw-r--r-- | framework/domain/CMakeLists.txt | 1 | ||||
-rw-r--r-- | framework/domain/contactcontroller.cpp | 33 | ||||
-rw-r--r-- | framework/domain/contactcontroller.h | 12 | ||||
-rw-r--r-- | framework/domain/mailplugin.cpp | 2 | ||||
-rw-r--r-- | framework/domain/peoplemodel.cpp | 101 | ||||
-rw-r--r-- | framework/domain/peoplemodel.h | 63 |
7 files changed, 223 insertions, 24 deletions
diff --git a/components/package/contents/ui/People.qml b/components/package/contents/ui/People.qml index 860609e0..ec017f1b 100644 --- a/components/package/contents/ui/People.qml +++ b/components/package/contents/ui/People.qml | |||
@@ -1,5 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | Copyright (C) 2017 Michael Bohlender, <michael.bohlender@kdemail.net> | 2 | Copyright (C) 2017 Michael Bohlender, <michael.bohlender@kdemail.net> |
3 | Copyright (C) 2017 Christian Mollekopf, <mollekopf@kolabsys.com> | ||
3 | 4 | ||
4 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
@@ -27,12 +28,17 @@ import org.kube.framework.domain 1.0 as KubeFramework | |||
27 | 28 | ||
28 | Popup { | 29 | Popup { |
29 | 30 | ||
31 | id: popup | ||
30 | modal: true | 32 | modal: true |
31 | 33 | ||
34 | property variant currentContact: null | ||
35 | |||
32 | Controls.SplitView { | 36 | Controls.SplitView { |
33 | anchors.fill: parent | 37 | anchors.fill: parent |
34 | 38 | ||
35 | Item { | 39 | Item { |
40 | id: contactList | ||
41 | |||
36 | height: parent.height | 42 | height: parent.height |
37 | width: Kirigami.Units.gridUnit * 14 | 43 | width: Kirigami.Units.gridUnit * 14 |
38 | 44 | ||
@@ -75,19 +81,40 @@ Popup { | |||
75 | topMargin: Kirigami.Units.smallSpacing | 81 | topMargin: Kirigami.Units.smallSpacing |
76 | } | 82 | } |
77 | 83 | ||
78 | model: 15 | 84 | model: KubeFramework.PeopleModel{} |
79 | clip: true | 85 | clip: true |
80 | 86 | ||
81 | ScrollBar.vertical: ScrollBar { | 87 | ScrollBar.vertical: ScrollBar { |
82 | id: scroll | 88 | id: scroll |
83 | } | 89 | } |
84 | 90 | ||
91 | onCurrentItemChanged: { | ||
92 | popup.currentContact = currentItem.currentData.domainObject; | ||
93 | } | ||
94 | |||
85 | delegate: Kirigami.AbstractListItem { | 95 | delegate: Kirigami.AbstractListItem { |
86 | height: Kirigami.Units.gridUnit * 2.5 | 96 | height: Kirigami.Units.gridUnit * 2.5 |
87 | width: listView.width - scroll.width | 97 | width: listView.width - scroll.width |
88 | 98 | ||
99 | property variant currentData: model | ||
100 | |||
89 | clip: true | 101 | clip: true |
90 | 102 | ||
103 | states: [ | ||
104 | State { | ||
105 | name: "selected" | ||
106 | when: ListView.isCurrentItem | ||
107 | PropertyChanges {target: background; color: Kirigami.Theme.highlightColor} | ||
108 | PropertyChanges {target: name; color: Kirigami.Theme.highlightedTextColor} | ||
109 | }, | ||
110 | State { | ||
111 | name: "hovered" | ||
112 | when: mouseArea.containsMouse | ||
113 | PropertyChanges {target: background; color: Kirigami.Theme.buttonHoverColor; opacity: 0.7} | ||
114 | PropertyChanges {target: name; color: Kirigami.Theme.highlightedTextColor} | ||
115 | } | ||
116 | ] | ||
117 | |||
91 | Avatar { | 118 | Avatar { |
92 | id: avatar | 119 | id: avatar |
93 | 120 | ||
@@ -100,7 +127,7 @@ Popup { | |||
100 | height: parent.height * 0.9 | 127 | height: parent.height * 0.9 |
101 | width: height | 128 | width: height |
102 | 129 | ||
103 | name: "Wolfgang Rosenzweig" | 130 | name: model.name |
104 | } | 131 | } |
105 | 132 | ||
106 | Text { | 133 | Text { |
@@ -112,7 +139,7 @@ Popup { | |||
112 | verticalCenter: avatar.verticalCenter | 139 | verticalCenter: avatar.verticalCenter |
113 | } | 140 | } |
114 | 141 | ||
115 | text: "Wolfgang Rosenzweig" | 142 | text: model.name |
116 | color: Kirigami.Theme.textColor | 143 | color: Kirigami.Theme.textColor |
117 | } | 144 | } |
118 | } | 145 | } |
@@ -120,9 +147,9 @@ Popup { | |||
120 | } | 147 | } |
121 | 148 | ||
122 | Item { | 149 | Item { |
123 | |||
124 | KubeFramework.ContactController { | 150 | KubeFramework.ContactController { |
125 | id: contactController | 151 | id: contactController |
152 | contact: popup.currentContact | ||
126 | } | 153 | } |
127 | 154 | ||
128 | height: parent.height | 155 | height: parent.height |
diff --git a/framework/domain/CMakeLists.txt b/framework/domain/CMakeLists.txt index 9abc54b0..b3f7acc5 100644 --- a/framework/domain/CMakeLists.txt +++ b/framework/domain/CMakeLists.txt | |||
@@ -25,6 +25,7 @@ set(mailplugin_SRCS | |||
25 | foldercontroller.cpp | 25 | foldercontroller.cpp |
26 | mouseproxy.cpp | 26 | mouseproxy.cpp |
27 | contactcontroller.cpp | 27 | contactcontroller.cpp |
28 | peoplemodel.cpp | ||
28 | ) | 29 | ) |
29 | find_package(KF5 REQUIRED COMPONENTS Package) | 30 | find_package(KF5 REQUIRED COMPONENTS Package) |
30 | 31 | ||
diff --git a/framework/domain/contactcontroller.cpp b/framework/domain/contactcontroller.cpp index 0be90e77..a1a805c9 100644 --- a/framework/domain/contactcontroller.cpp +++ b/framework/domain/contactcontroller.cpp | |||
@@ -18,16 +18,17 @@ | |||
18 | 18 | ||
19 | #include "contactcontroller.h" | 19 | #include "contactcontroller.h" |
20 | 20 | ||
21 | #include <sink/applicationdomaintype.h> | ||
22 | |||
21 | ContactController::ContactController() | 23 | ContactController::ContactController() |
22 | : Kube::Controller(), | 24 | : Kube::Controller(), |
23 | action_save{new Kube::ControllerAction{this, &ContactController::save}} | 25 | action_save{new Kube::ControllerAction{this, &ContactController::save}} |
24 | { | 26 | { |
25 | loadContact("test"); | ||
26 | updateSaveAction(); | 27 | updateSaveAction(); |
27 | } | 28 | } |
28 | 29 | ||
29 | void ContactController::save() { | 30 | void ContactController::save() { |
30 | //TODO | 31 | qWarning() << "Saving is not implemented"; |
31 | } | 32 | } |
32 | 33 | ||
33 | void ContactController::updateSaveAction() | 34 | void ContactController::updateSaveAction() |
@@ -37,23 +38,31 @@ void ContactController::updateSaveAction() | |||
37 | 38 | ||
38 | void ContactController::loadContact(const QVariant &contact) | 39 | void ContactController::loadContact(const QVariant &contact) |
39 | { | 40 | { |
40 | setName("Anita Rosenzweig"); | 41 | if (auto c = contact.value<Sink::ApplicationDomain::Contact::Ptr>()) { |
41 | m_emails << "rosenzweig@kolabnow.com" << "wolfi@kolabnow.com"; | 42 | setName(c->getFn()); |
43 | QStringList emails; | ||
44 | for (const auto &e : c->getEmails()) { | ||
45 | emails << e; | ||
46 | } | ||
47 | setEmails(emails); | ||
48 | } | ||
42 | } | 49 | } |
43 | 50 | ||
44 | void ContactController::removeEmail(const QString &email) | 51 | QVariant ContactController::contact() const |
45 | { | 52 | { |
46 | m_emails.removeOne(email); | 53 | return QVariant{}; |
47 | emit emailsChanged(); | ||
48 | } | 54 | } |
49 | 55 | ||
50 | void ContactController::addEmail(const QString &email) | 56 | void ContactController::removeEmail(const QString &email) |
51 | { | 57 | { |
52 | m_emails << email; | 58 | auto emails = getEmails(); |
53 | emit emailsChanged(); | 59 | emails.removeAll(email); |
60 | setEmails(emails); | ||
54 | } | 61 | } |
55 | 62 | ||
56 | QStringList ContactController::emails() const | 63 | void ContactController::addEmail(const QString &email) |
57 | { | 64 | { |
58 | return m_emails; | 65 | auto emails = getEmails(); |
66 | emails.append(email); | ||
67 | setEmails(emails); | ||
59 | } | 68 | } |
diff --git a/framework/domain/contactcontroller.h b/framework/domain/contactcontroller.h index d9bca563..d1973d9c 100644 --- a/framework/domain/contactcontroller.h +++ b/framework/domain/contactcontroller.h | |||
@@ -29,28 +29,24 @@ class ContactController : public Kube::Controller | |||
29 | { | 29 | { |
30 | Q_OBJECT | 30 | Q_OBJECT |
31 | 31 | ||
32 | Q_PROPERTY(QStringList emails READ emails NOTIFY emailsChanged) | 32 | // Input properties |
33 | Q_PROPERTY(QVariant contact READ contact WRITE loadContact) | ||
33 | 34 | ||
34 | //Interface properties | 35 | //Interface properties |
35 | KUBE_CONTROLLER_PROPERTY(QString, Name, name) | 36 | KUBE_CONTROLLER_PROPERTY(QString, Name, name) |
37 | KUBE_CONTROLLER_PROPERTY(QStringList, Emails, emails) | ||
36 | 38 | ||
37 | KUBE_CONTROLLER_ACTION(save) | 39 | KUBE_CONTROLLER_ACTION(save) |
38 | 40 | ||
39 | public: | 41 | public: |
40 | explicit ContactController(); | 42 | explicit ContactController(); |
41 | 43 | ||
42 | QStringList emails() const; | ||
43 | |||
44 | Q_INVOKABLE void loadContact(const QVariant &contact); | 44 | Q_INVOKABLE void loadContact(const QVariant &contact); |
45 | Q_INVOKABLE void removeEmail(const QString &email); | 45 | Q_INVOKABLE void removeEmail(const QString &email); |
46 | Q_INVOKABLE void addEmail(const QString &email); | 46 | Q_INVOKABLE void addEmail(const QString &email); |
47 | 47 | ||
48 | signals: | 48 | QVariant contact() const; |
49 | void emailsChanged(); | ||
50 | 49 | ||
51 | private slots: | 50 | private slots: |
52 | void updateSaveAction(); | 51 | void updateSaveAction(); |
53 | |||
54 | private: | ||
55 | QStringList m_emails; | ||
56 | }; | 52 | }; |
diff --git a/framework/domain/mailplugin.cpp b/framework/domain/mailplugin.cpp index fba6c458..12b9a7ce 100644 --- a/framework/domain/mailplugin.cpp +++ b/framework/domain/mailplugin.cpp | |||
@@ -31,6 +31,7 @@ | |||
31 | #include "foldercontroller.h" | 31 | #include "foldercontroller.h" |
32 | #include "mouseproxy.h" | 32 | #include "mouseproxy.h" |
33 | #include "contactcontroller.h" | 33 | #include "contactcontroller.h" |
34 | #include "peoplemodel.h" | ||
34 | 35 | ||
35 | #include <QtQml> | 36 | #include <QtQml> |
36 | 37 | ||
@@ -49,4 +50,5 @@ void MailPlugin::registerTypes (const char *uri) | |||
49 | qmlRegisterType<FolderController>(uri, 1, 0, "FolderController"); | 50 | qmlRegisterType<FolderController>(uri, 1, 0, "FolderController"); |
50 | qmlRegisterType<MouseProxy>(uri, 1, 0, "MouseProxy"); | 51 | qmlRegisterType<MouseProxy>(uri, 1, 0, "MouseProxy"); |
51 | qmlRegisterType<ContactController>(uri, 1, 0,"ContactController"); | 52 | qmlRegisterType<ContactController>(uri, 1, 0,"ContactController"); |
53 | qmlRegisterType<PeopleModel>(uri, 1, 0,"PeopleModel"); | ||
52 | } | 54 | } |
diff --git a/framework/domain/peoplemodel.cpp b/framework/domain/peoplemodel.cpp new file mode 100644 index 00000000..7cc2f3fa --- /dev/null +++ b/framework/domain/peoplemodel.cpp | |||
@@ -0,0 +1,101 @@ | |||
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 | #include "peoplemodel.h" | ||
21 | |||
22 | #include <sink/standardqueries.h> | ||
23 | #include <sink/store.h> | ||
24 | |||
25 | PeopleModel::PeopleModel(QObject *parent) | ||
26 | : QSortFilterProxyModel() | ||
27 | { | ||
28 | using namespace Sink::ApplicationDomain; | ||
29 | |||
30 | setDynamicSortFilter(true); | ||
31 | sort(0, Qt::DescendingOrder); | ||
32 | Sink::Query query; | ||
33 | query.setFlags(Sink::Query::LiveQuery); | ||
34 | query.request<Contact::Fn>(); | ||
35 | query.request<Contact::Emails>(); | ||
36 | query.request<Contact::Addressbook>(); | ||
37 | query.request<Contact::Vcard>(); | ||
38 | runQuery(query); | ||
39 | } | ||
40 | |||
41 | PeopleModel::~PeopleModel() | ||
42 | { | ||
43 | |||
44 | } | ||
45 | |||
46 | QHash< int, QByteArray > PeopleModel::roleNames() const | ||
47 | { | ||
48 | static QHash<int, QByteArray> roles = { | ||
49 | {Name, "name"}, | ||
50 | {Emails, "emails"}, | ||
51 | {Addressbook, "addressbook"}, | ||
52 | {Type, "type"}, | ||
53 | {DomainObject, "domainObject"} | ||
54 | }; | ||
55 | return roles; | ||
56 | } | ||
57 | |||
58 | QVariant PeopleModel::data(const QModelIndex &idx, int role) const | ||
59 | { | ||
60 | auto srcIdx = mapToSource(idx); | ||
61 | auto contact = srcIdx.data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Contact::Ptr>(); | ||
62 | switch (role) { | ||
63 | case Name: | ||
64 | return contact->getFn(); | ||
65 | case Emails: | ||
66 | return QVariant::fromValue(contact->getEmails()); | ||
67 | case Addressbook: | ||
68 | return contact->getAddressbook(); | ||
69 | case Type: | ||
70 | return "contact"; | ||
71 | case DomainObject: | ||
72 | return QVariant::fromValue(contact); | ||
73 | } | ||
74 | return QSortFilterProxyModel::data(idx, role); | ||
75 | } | ||
76 | |||
77 | bool PeopleModel::lessThan(const QModelIndex &left, const QModelIndex &right) const | ||
78 | { | ||
79 | const auto leftName = left.data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Contact::Ptr>()->getFn(); | ||
80 | const auto rightName = right.data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Contact::Ptr>()->getFn(); | ||
81 | return leftName < rightName; | ||
82 | } | ||
83 | |||
84 | void PeopleModel::runQuery(const Sink::Query &query) | ||
85 | { | ||
86 | mModel = Sink::Store::loadModel<Sink::ApplicationDomain::Contact>(query); | ||
87 | setSourceModel(mModel.data()); | ||
88 | } | ||
89 | |||
90 | void PeopleModel::setAddressbook(const QVariant &parentFolder) | ||
91 | { | ||
92 | //TODO filter query by addressbook | ||
93 | qWarning() << "The addressbook filter is not yet implemented"; | ||
94 | } | ||
95 | |||
96 | QVariant PeopleModel::addressbook() const | ||
97 | { | ||
98 | return QVariant(); | ||
99 | } | ||
100 | |||
101 | |||
diff --git a/framework/domain/peoplemodel.h b/framework/domain/peoplemodel.h new file mode 100644 index 00000000..419d59a6 --- /dev/null +++ b/framework/domain/peoplemodel.h | |||
@@ -0,0 +1,63 @@ | |||
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 <QSortFilterProxyModel> | ||
24 | #include <QSharedPointer> | ||
25 | |||
26 | namespace Sink { | ||
27 | class Query; | ||
28 | }; | ||
29 | |||
30 | /** | ||
31 | * A model that mixes addressbooks, contact groups and contacts | ||
32 | */ | ||
33 | class PeopleModel : public QSortFilterProxyModel | ||
34 | { | ||
35 | Q_OBJECT | ||
36 | Q_PROPERTY (QVariant addressbook READ addressbook WRITE setAddressbook) | ||
37 | |||
38 | public: | ||
39 | PeopleModel(QObject *parent = Q_NULLPTR); | ||
40 | ~PeopleModel(); | ||
41 | |||
42 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; | ||
43 | |||
44 | bool lessThan(const QModelIndex &left, const QModelIndex &right) const Q_DECL_OVERRIDE; | ||
45 | |||
46 | enum Roles { | ||
47 | Name = Qt::UserRole + 1, | ||
48 | Type, | ||
49 | Emails, | ||
50 | Addressbook, | ||
51 | DomainObject | ||
52 | }; | ||
53 | |||
54 | QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE; | ||
55 | |||
56 | void runQuery(const Sink::Query &query); | ||
57 | |||
58 | void setAddressbook(const QVariant &parentFolder); | ||
59 | QVariant addressbook() const; | ||
60 | |||
61 | private: | ||
62 | QSharedPointer<QAbstractItemModel> mModel; | ||
63 | }; | ||