diff options
-rw-r--r-- | components/package/contents/ui/Composer.qml | 2 | ||||
-rw-r--r-- | framework/domain/CMakeLists.txt | 1 | ||||
-rw-r--r-- | framework/domain/composercontroller.cpp | 16 | ||||
-rw-r--r-- | framework/domain/identitiesmodel.cpp | 93 | ||||
-rw-r--r-- | framework/domain/identitiesmodel.h | 60 |
5 files changed, 165 insertions, 7 deletions
diff --git a/components/package/contents/ui/Composer.qml b/components/package/contents/ui/Composer.qml index 34fd3ca4..1bd96a2b 100644 --- a/components/package/contents/ui/Composer.qml +++ b/components/package/contents/ui/Composer.qml | |||
@@ -69,7 +69,7 @@ Item { | |||
69 | ComboBox { | 69 | ComboBox { |
70 | id: identityCombo | 70 | id: identityCombo |
71 | model: composer.identityModel | 71 | model: composer.identityModel |
72 | textRole: "name" | 72 | textRole: "displayName" |
73 | 73 | ||
74 | Layout.fillWidth: true | 74 | Layout.fillWidth: true |
75 | 75 | ||
diff --git a/framework/domain/CMakeLists.txt b/framework/domain/CMakeLists.txt index f40463be..b3d47750 100644 --- a/framework/domain/CMakeLists.txt +++ b/framework/domain/CMakeLists.txt | |||
@@ -15,6 +15,7 @@ set(mailplugin_SRCS | |||
15 | accountfactory.cpp | 15 | accountfactory.cpp |
16 | accountscontroller.cpp | 16 | accountscontroller.cpp |
17 | accountsmodel.cpp | 17 | accountsmodel.cpp |
18 | identitiesmodel.cpp | ||
18 | ) | 19 | ) |
19 | add_definitions(-DMAIL_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data") | 20 | add_definitions(-DMAIL_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data") |
20 | 21 | ||
diff --git a/framework/domain/composercontroller.cpp b/framework/domain/composercontroller.cpp index a383de26..bca90d33 100644 --- a/framework/domain/composercontroller.cpp +++ b/framework/domain/composercontroller.cpp | |||
@@ -29,6 +29,7 @@ | |||
29 | #include <QQmlEngine> | 29 | #include <QQmlEngine> |
30 | 30 | ||
31 | #include "accountsmodel.h" | 31 | #include "accountsmodel.h" |
32 | #include "identitiesmodel.h" | ||
32 | #include "mailtemplates.h" | 33 | #include "mailtemplates.h" |
33 | 34 | ||
34 | ComposerController::ComposerController(QObject *parent) : QObject(parent) | 35 | ComposerController::ComposerController(QObject *parent) : QObject(parent) |
@@ -102,9 +103,9 @@ void ComposerController::setBody(const QString &body) | |||
102 | 103 | ||
103 | QAbstractItemModel *ComposerController::identityModel() const | 104 | QAbstractItemModel *ComposerController::identityModel() const |
104 | { | 105 | { |
105 | static auto accountsModel = new AccountsModel(); | 106 | static auto model = new IdentitiesModel(); |
106 | QQmlEngine::setObjectOwnership(accountsModel, QQmlEngine::CppOwnership); | 107 | QQmlEngine::setObjectOwnership(model, QQmlEngine::CppOwnership); |
107 | return accountsModel;; | 108 | return model; |
108 | } | 109 | } |
109 | 110 | ||
110 | QStringList ComposerController::attachemts() const | 111 | QStringList ComposerController::attachemts() const |
@@ -155,8 +156,11 @@ KMime::Message::Ptr ComposerController::assembleMessage() | |||
155 | KEmailAddress::splitAddress(to.toUtf8(), displayName, addrSpec, comment); | 156 | KEmailAddress::splitAddress(to.toUtf8(), displayName, addrSpec, comment); |
156 | mail->to(true)->addAddress(addrSpec, displayName); | 157 | mail->to(true)->addAddress(addrSpec, displayName); |
157 | } | 158 | } |
158 | //FIXME set "from" from identity (or do that in the action directly?) | 159 | auto currentIndex = identityModel()->index(m_currentAccountIndex, 0); |
159 | // mail->from(true)->addAddress("test@example.com", "John Doe"); | 160 | KMime::Types::Mailbox mb; |
161 | mb.setName(currentIndex.data(IdentitiesModel::Username).toString()); | ||
162 | mb.setAddress(currentIndex.data(IdentitiesModel::Address).toString().toUtf8()); | ||
163 | mail->from(true)->addAddress(mb); | ||
160 | mail->subject(true)->fromUnicodeString(m_subject, "utf-8"); | 164 | mail->subject(true)->fromUnicodeString(m_subject, "utf-8"); |
161 | mail->setBody(m_body.toUtf8()); | 165 | mail->setBody(m_body.toUtf8()); |
162 | mail->assemble(); | 166 | mail->assemble(); |
@@ -166,7 +170,7 @@ KMime::Message::Ptr ComposerController::assembleMessage() | |||
166 | void ComposerController::send() | 170 | void ComposerController::send() |
167 | { | 171 | { |
168 | auto mail = assembleMessage(); | 172 | auto mail = assembleMessage(); |
169 | auto currentAccountId = identityModel()->index(m_currentAccountIndex, 0).data(AccountsModel::AccountId).toByteArray(); | 173 | auto currentAccountId = identityModel()->index(m_currentAccountIndex, 0).data(IdentitiesModel::AccountId).toByteArray(); |
170 | 174 | ||
171 | Kube::Context context; | 175 | Kube::Context context; |
172 | context.setProperty("message", QVariant::fromValue(mail)); | 176 | context.setProperty("message", QVariant::fromValue(mail)); |
diff --git a/framework/domain/identitiesmodel.cpp b/framework/domain/identitiesmodel.cpp new file mode 100644 index 00000000..adb5d625 --- /dev/null +++ b/framework/domain/identitiesmodel.cpp | |||
@@ -0,0 +1,93 @@ | |||
1 | /* | ||
2 | Copyright (c) 2016 Christian Mollekopf <mollekopf@kolabsys.com> | ||
3 | |||
4 | This library is free software; you can redistribute it and/or modify it | ||
5 | under the terms of the GNU Library General Public License as published by | ||
6 | the Free Software Foundation; either version 2 of the License, or (at your | ||
7 | option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, but WITHOUT | ||
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public | ||
12 | License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to the | ||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
17 | 02110-1301, USA. | ||
18 | */ | ||
19 | #include "identitiesmodel.h" | ||
20 | #include <sink/store.h> | ||
21 | |||
22 | IdentitiesModel::IdentitiesModel(QObject *parent) : QIdentityProxyModel() | ||
23 | { | ||
24 | Sink::Query query; | ||
25 | query.liveQuery = true; | ||
26 | query.requestedProperties << "name" << "username" << "address" << "account"; | ||
27 | runQuery(query); | ||
28 | } | ||
29 | |||
30 | IdentitiesModel::~IdentitiesModel() | ||
31 | { | ||
32 | |||
33 | } | ||
34 | |||
35 | QHash< int, QByteArray > IdentitiesModel::roleNames() const | ||
36 | { | ||
37 | QHash<int, QByteArray> roles; | ||
38 | |||
39 | roles[Name] = "name"; | ||
40 | roles[Username] = "username"; | ||
41 | roles[Address] = "address"; | ||
42 | roles[IdentityId] = "identityId"; | ||
43 | roles[AccountId] = "accountId"; | ||
44 | roles[AccountName] = "accountName"; | ||
45 | roles[AccountIcon] = "accountIcon"; | ||
46 | roles[DisplayName] = "displayName"; | ||
47 | |||
48 | return roles; | ||
49 | } | ||
50 | |||
51 | QVariant IdentitiesModel::data(const QModelIndex &idx, int role) const | ||
52 | { | ||
53 | auto srcIdx = mapToSource(idx); | ||
54 | switch (role) { | ||
55 | case Name: | ||
56 | return srcIdx.sibling(srcIdx.row(), 0).data(Qt::DisplayRole).toString(); | ||
57 | case Username: | ||
58 | return srcIdx.sibling(srcIdx.row(), 1).data(Qt::DisplayRole).toString(); | ||
59 | case Address: | ||
60 | return srcIdx.sibling(srcIdx.row(), 2).data(Qt::DisplayRole).toString(); | ||
61 | case IdentityId: | ||
62 | return srcIdx.data(Sink::Store::DomainObjectBaseRole).value<Sink::ApplicationDomain::ApplicationDomainType::Ptr>()->identifier(); | ||
63 | case AccountId: | ||
64 | return srcIdx.data(Sink::Store::DomainObjectBaseRole).value<Sink::ApplicationDomain::ApplicationDomainType::Ptr>()->getProperty("account").toByteArray(); | ||
65 | case AccountName: { | ||
66 | const auto accountId = srcIdx.sibling(srcIdx.row(), 3).data(Qt::DisplayRole).toByteArray(); | ||
67 | return mAccountNames.value(accountId); | ||
68 | } | ||
69 | case AccountIcon: { | ||
70 | const auto accountId = srcIdx.sibling(srcIdx.row(), 3).data(Qt::DisplayRole).toByteArray(); | ||
71 | return mAccountIcons.value(accountId); | ||
72 | } | ||
73 | case DisplayName: { | ||
74 | return data(idx, AccountName).toString() + ": " + data(idx, Username).toString() + ", " + data(idx, Address).toString(); | ||
75 | } | ||
76 | } | ||
77 | return QIdentityProxyModel::data(idx, role); | ||
78 | } | ||
79 | |||
80 | void IdentitiesModel::runQuery(const Sink::Query &query) | ||
81 | { | ||
82 | mModel = Sink::Store::loadModel<Sink::ApplicationDomain::Identity>(query); | ||
83 | setSourceModel(mModel.data()); | ||
84 | |||
85 | Sink::Store::fetchAll<Sink::ApplicationDomain::SinkAccount>(Sink::Query()) | ||
86 | .then<void, QList<Sink::ApplicationDomain::SinkAccount::Ptr> >([this](const QList<Sink::ApplicationDomain::SinkAccount::Ptr> &accounts) { | ||
87 | for (const auto &account : accounts) { | ||
88 | mAccountNames.insert(account->identifier(), account->getProperty("name").toString()); | ||
89 | mAccountIcons.insert(account->identifier(), account->getProperty("icon").toString()); | ||
90 | } | ||
91 | emit layoutChanged(); | ||
92 | }).exec(); | ||
93 | } | ||
diff --git a/framework/domain/identitiesmodel.h b/framework/domain/identitiesmodel.h new file mode 100644 index 00000000..9b172251 --- /dev/null +++ b/framework/domain/identitiesmodel.h | |||
@@ -0,0 +1,60 @@ | |||
1 | /* | ||
2 | Copyright (c) 2016 Christian Mollekopf <mollekopf@kolabsys.com> | ||
3 | |||
4 | This library is free software; you can redistribute it and/or modify it | ||
5 | under the terms of the GNU Library General Public License as published by | ||
6 | the Free Software Foundation; either version 2 of the License, or (at your | ||
7 | option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, but WITHOUT | ||
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public | ||
12 | License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to the | ||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
17 | 02110-1301, USA. | ||
18 | */ | ||
19 | |||
20 | #pragma once | ||
21 | |||
22 | #include <QObject> | ||
23 | #include <QIdentityProxyModel> | ||
24 | #include <QSharedPointer> | ||
25 | #include <QStringList> | ||
26 | |||
27 | namespace Sink { | ||
28 | class Query; | ||
29 | } | ||
30 | |||
31 | class IdentitiesModel : public QIdentityProxyModel | ||
32 | { | ||
33 | Q_OBJECT | ||
34 | |||
35 | public: | ||
36 | IdentitiesModel(QObject *parent = Q_NULLPTR); | ||
37 | ~IdentitiesModel(); | ||
38 | |||
39 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; | ||
40 | |||
41 | enum Roles { | ||
42 | Name = Qt::UserRole + 1, | ||
43 | Username, | ||
44 | Address, | ||
45 | IdentityId, | ||
46 | AccountId, | ||
47 | AccountName, | ||
48 | AccountIcon, | ||
49 | DisplayName | ||
50 | }; | ||
51 | Q_ENUMS(Roles) | ||
52 | |||
53 | QHash<int, QByteArray> roleNames() const; | ||
54 | |||
55 | private: | ||
56 | void runQuery(const Sink::Query &query); | ||
57 | QSharedPointer<QAbstractItemModel> mModel; | ||
58 | QHash <QByteArray, QString> mAccountNames; | ||
59 | QHash <QByteArray, QString> mAccountIcons; | ||
60 | }; | ||