diff options
-rw-r--r-- | accounts/maildir/maildirsettings.cpp | 33 | ||||
-rw-r--r-- | accounts/maildir/maildirsettings.h | 6 | ||||
-rw-r--r-- | accounts/maildir/package/contents/ui/MaildirAccountSettings.qml | 16 | ||||
-rw-r--r-- | accounts/maildir/tests/settingstest.cpp | 13 | ||||
-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 |
9 files changed, 230 insertions, 10 deletions
diff --git a/accounts/maildir/maildirsettings.cpp b/accounts/maildir/maildirsettings.cpp index fa30851c..e47b834f 100644 --- a/accounts/maildir/maildirsettings.cpp +++ b/accounts/maildir/maildirsettings.cpp | |||
@@ -82,6 +82,18 @@ void MaildirSettings::setAccountIdentifier(const QByteArray &id) | |||
82 | [](int errorCode, const QString &errorMessage) { | 82 | [](int errorCode, const QString &errorMessage) { |
83 | qWarning() << "Failed to find the maildir resource: " << errorMessage; | 83 | qWarning() << "Failed to find the maildir resource: " << errorMessage; |
84 | }).exec(); | 84 | }).exec(); |
85 | |||
86 | //FIXME this assumes that we only ever have one identity per account | ||
87 | Sink::Store::fetchOne<Sink::ApplicationDomain::Identity>(Sink::Query::PropertyFilter("account", QVariant::fromValue(id))) | ||
88 | .then<void, Sink::ApplicationDomain::Identity>([this](const Sink::ApplicationDomain::Identity &identity) { | ||
89 | mIdentityIdentifier = identity.identifier(); | ||
90 | mUsername = identity.getProperty("username").toString(); | ||
91 | mEmailAddress = identity.getProperty("address").toString(); | ||
92 | emit identityChanged(); | ||
93 | }, | ||
94 | [](int errorCode, const QString &errorMessage) { | ||
95 | qWarning() << "Failed to find the identity resource: " << errorMessage; | ||
96 | }).exec(); | ||
85 | } | 97 | } |
86 | 98 | ||
87 | QByteArray MaildirSettings::accountIdentifier() const | 99 | QByteArray MaildirSettings::accountIdentifier() const |
@@ -207,6 +219,27 @@ void MaildirSettings::save() | |||
207 | }) | 219 | }) |
208 | .exec(); | 220 | .exec(); |
209 | } | 221 | } |
222 | |||
223 | if (!mIdentityIdentifier.isEmpty()) { | ||
224 | Sink::ApplicationDomain::Identity identity(mMailtransportIdentifier); | ||
225 | identity.setProperty("username", mUsername); | ||
226 | identity.setProperty("address", mEmailAddress); | ||
227 | Sink::Store::modify(identity).then<void>([](){}, [](int errorCode, const QString &errorMessage) { | ||
228 | qWarning() << "Error while modifying identity: " << errorMessage; | ||
229 | }) | ||
230 | .exec(); | ||
231 | } else { | ||
232 | auto identity = Sink::ApplicationDomain::ApplicationDomainType::createEntity<Sink::ApplicationDomain::Identity>(); | ||
233 | mIdentityIdentifier = identity.identifier(); | ||
234 | identity.setProperty("account", mAccountIdentifier); | ||
235 | identity.setProperty("username", mUsername); | ||
236 | identity.setProperty("address", mEmailAddress); | ||
237 | Sink::Store::create(identity).then<void>([]() {}, | ||
238 | [](int errorCode, const QString &errorMessage) { | ||
239 | qWarning() << "Error while creating identity: " << errorMessage; | ||
240 | }) | ||
241 | .exec(); | ||
242 | } | ||
210 | } | 243 | } |
211 | 244 | ||
212 | void MaildirSettings::remove() | 245 | void MaildirSettings::remove() |
diff --git a/accounts/maildir/maildirsettings.h b/accounts/maildir/maildirsettings.h index be69ffb8..a02944d9 100644 --- a/accounts/maildir/maildirsettings.h +++ b/accounts/maildir/maildirsettings.h | |||
@@ -29,6 +29,8 @@ class MaildirSettings : public QObject | |||
29 | Q_PROPERTY(QValidator* pathValidator READ pathValidator CONSTANT) | 29 | Q_PROPERTY(QValidator* pathValidator READ pathValidator CONSTANT) |
30 | Q_PROPERTY(QString icon MEMBER mIcon NOTIFY changed) | 30 | Q_PROPERTY(QString icon MEMBER mIcon NOTIFY changed) |
31 | Q_PROPERTY(QString accountName MEMBER mName NOTIFY changed) | 31 | Q_PROPERTY(QString accountName MEMBER mName NOTIFY changed) |
32 | Q_PROPERTY(QString userName MEMBER mUsername NOTIFY identityChanged) | ||
33 | Q_PROPERTY(QString emailAddress MEMBER mEmailAddress NOTIFY identityChanged) | ||
32 | Q_PROPERTY(QString smtpServer MEMBER mSmtpServer NOTIFY smtpResourceChanged) | 34 | Q_PROPERTY(QString smtpServer MEMBER mSmtpServer NOTIFY smtpResourceChanged) |
33 | Q_PROPERTY(QValidator* smtpServerValidator READ smtpServerValidator CONSTANT) | 35 | Q_PROPERTY(QValidator* smtpServerValidator READ smtpServerValidator CONSTANT) |
34 | Q_PROPERTY(QString smtpUsername MEMBER mSmtpUsername NOTIFY smtpResourceChanged) | 36 | Q_PROPERTY(QString smtpUsername MEMBER mSmtpUsername NOTIFY smtpResourceChanged) |
@@ -52,15 +54,19 @@ public: | |||
52 | signals: | 54 | signals: |
53 | void pathChanged(); | 55 | void pathChanged(); |
54 | void smtpResourceChanged(); | 56 | void smtpResourceChanged(); |
57 | void identityChanged(); | ||
55 | void changed(); | 58 | void changed(); |
56 | 59 | ||
57 | private: | 60 | private: |
58 | QByteArray mIdentifier; | 61 | QByteArray mIdentifier; |
59 | QByteArray mAccountIdentifier; | 62 | QByteArray mAccountIdentifier; |
60 | QByteArray mMailtransportIdentifier; | 63 | QByteArray mMailtransportIdentifier; |
64 | QByteArray mIdentityIdentifier; | ||
61 | QString mPath; | 65 | QString mPath; |
62 | QString mIcon; | 66 | QString mIcon; |
63 | QString mName; | 67 | QString mName; |
68 | QString mUsername; | ||
69 | QString mEmailAddress; | ||
64 | QString mSmtpServer; | 70 | QString mSmtpServer; |
65 | QString mSmtpUsername; | 71 | QString mSmtpUsername; |
66 | QString mSmtpPassword; | 72 | QString mSmtpPassword; |
diff --git a/accounts/maildir/package/contents/ui/MaildirAccountSettings.qml b/accounts/maildir/package/contents/ui/MaildirAccountSettings.qml index e508a475..d9d0741d 100644 --- a/accounts/maildir/package/contents/ui/MaildirAccountSettings.qml +++ b/accounts/maildir/package/contents/ui/MaildirAccountSettings.qml | |||
@@ -53,6 +53,22 @@ Rectangle { | |||
53 | onTextChanged: { maildirSettings.accountName = text; } | 53 | onTextChanged: { maildirSettings.accountName = text; } |
54 | } | 54 | } |
55 | 55 | ||
56 | Label { text: "User Name" } | ||
57 | TextField { | ||
58 | placeholderText: "Your Name" | ||
59 | Layout.fillWidth: true | ||
60 | text: maildirSettings.userName | ||
61 | onTextChanged: { maildirSettings.userName = text; } | ||
62 | } | ||
63 | |||
64 | Label { text: "Email Address" } | ||
65 | TextField { | ||
66 | placeholderText: "Your EMail Address" | ||
67 | Layout.fillWidth: true | ||
68 | text: maildirSettings.emailAddress | ||
69 | onTextChanged: { maildirSettings.emailAddress = text; } | ||
70 | } | ||
71 | |||
56 | Text { | 72 | Text { |
57 | Layout.columnSpan: 2 | 73 | Layout.columnSpan: 2 |
58 | Layout.fillWidth: true | 74 | Layout.fillWidth: true |
diff --git a/accounts/maildir/tests/settingstest.cpp b/accounts/maildir/tests/settingstest.cpp index 07665c24..1967bcfc 100644 --- a/accounts/maildir/tests/settingstest.cpp +++ b/accounts/maildir/tests/settingstest.cpp | |||
@@ -26,6 +26,8 @@ private slots: | |||
26 | auto smtpServer = QString("smtpserver"); | 26 | auto smtpServer = QString("smtpserver"); |
27 | auto smtpUsername = QString("username"); | 27 | auto smtpUsername = QString("username"); |
28 | auto smtpPassword = QString("password"); | 28 | auto smtpPassword = QString("password"); |
29 | auto username = QString("username"); | ||
30 | auto emailAddress = QString("emailAddress"); | ||
29 | 31 | ||
30 | MaildirSettings settings; | 32 | MaildirSettings settings; |
31 | settings.setAccountIdentifier(accountId); | 33 | settings.setAccountIdentifier(accountId); |
@@ -33,6 +35,8 @@ private slots: | |||
33 | settings.setProperty("smtpServer", smtpServer); | 35 | settings.setProperty("smtpServer", smtpServer); |
34 | settings.setProperty("smtpUsername", smtpUsername); | 36 | settings.setProperty("smtpUsername", smtpUsername); |
35 | settings.setProperty("smtpPassword", smtpPassword); | 37 | settings.setProperty("smtpPassword", smtpPassword); |
38 | settings.setProperty("username", username); | ||
39 | settings.setProperty("emailAddress", emailAddress); | ||
36 | settings.save(); | 40 | settings.save(); |
37 | 41 | ||
38 | Sink::Store::fetchAll<Sink::ApplicationDomain::SinkResource>(Sink::Query()).then<void, QList<Sink::ApplicationDomain::SinkResource>>([](const QList<Sink::ApplicationDomain::SinkResource> &resources) { | 42 | Sink::Store::fetchAll<Sink::ApplicationDomain::SinkResource>(Sink::Query()).then<void, QList<Sink::ApplicationDomain::SinkResource>>([](const QList<Sink::ApplicationDomain::SinkResource> &resources) { |
@@ -46,20 +50,23 @@ private slots: | |||
46 | QSignalSpy spy(&readSettings, &MaildirSettings::pathChanged); | 50 | QSignalSpy spy(&readSettings, &MaildirSettings::pathChanged); |
47 | QSignalSpy spy1(&readSettings, &MaildirSettings::smtpResourceChanged); | 51 | QSignalSpy spy1(&readSettings, &MaildirSettings::smtpResourceChanged); |
48 | readSettings.setAccountIdentifier(accountId); | 52 | readSettings.setAccountIdentifier(accountId); |
49 | QTRY_VERIFY(spy.count()); | 53 | //Once for clear and once for once for the new setting |
50 | QTRY_VERIFY(spy1.count()); | 54 | QTRY_COMPARE(spy.count(), 2); |
55 | QTRY_COMPARE(spy1.count(), 2); | ||
51 | QVERIFY(!readSettings.accountIdentifier().isEmpty()); | 56 | QVERIFY(!readSettings.accountIdentifier().isEmpty()); |
52 | QCOMPARE(readSettings.path().toString(), maildirPath); | 57 | QCOMPARE(readSettings.path().toString(), maildirPath); |
53 | QCOMPARE(readSettings.property("smtpServer").toString(), smtpServer); | 58 | QCOMPARE(readSettings.property("smtpServer").toString(), smtpServer); |
54 | QCOMPARE(readSettings.property("smtpUsername").toString(), smtpUsername); | 59 | QCOMPARE(readSettings.property("smtpUsername").toString(), smtpUsername); |
55 | QCOMPARE(readSettings.property("smtpPassword").toString(), smtpPassword); | 60 | QCOMPARE(readSettings.property("smtpPassword").toString(), smtpPassword); |
61 | QCOMPARE(readSettings.property("username").toString(), smtpUsername); | ||
62 | QCOMPARE(readSettings.property("emailAddress").toString(), smtpPassword); | ||
56 | } | 63 | } |
57 | 64 | ||
58 | { | 65 | { |
59 | MaildirSettings settings; | 66 | MaildirSettings settings; |
60 | QSignalSpy spy(&settings, &MaildirSettings::pathChanged); | 67 | QSignalSpy spy(&settings, &MaildirSettings::pathChanged); |
61 | settings.setAccountIdentifier(accountId); | 68 | settings.setAccountIdentifier(accountId); |
62 | QTRY_VERIFY(spy.count()); | 69 | QTRY_COMPARE(spy.count(), 2); |
63 | settings.remove(); | 70 | settings.remove(); |
64 | } | 71 | } |
65 | 72 | ||
diff --git a/components/package/contents/ui/Composer.qml b/components/package/contents/ui/Composer.qml index 99b518b1..8c6f9c77 100644 --- a/components/package/contents/ui/Composer.qml +++ b/components/package/contents/ui/Composer.qml | |||
@@ -68,7 +68,7 @@ Item { | |||
68 | ComboBox { | 68 | ComboBox { |
69 | id: identityCombo | 69 | id: identityCombo |
70 | model: composer.identityModel | 70 | model: composer.identityModel |
71 | textRole: "name" | 71 | textRole: "displayName" |
72 | 72 | ||
73 | Layout.fillWidth: true | 73 | Layout.fillWidth: true |
74 | 74 | ||
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 | }; | ||