summaryrefslogtreecommitdiffstats
path: root/framework/domain
diff options
context:
space:
mode:
Diffstat (limited to 'framework/domain')
-rw-r--r--framework/domain/accountfactory.cpp4
-rw-r--r--framework/domain/accountscontroller.cpp10
-rw-r--r--framework/domain/actions/sinkactions.cpp60
-rw-r--r--framework/domain/composercontroller.cpp2
-rw-r--r--framework/domain/folderlistmodel.cpp37
-rw-r--r--framework/domain/identitiesmodel.cpp2
-rw-r--r--framework/domain/maillistmodel.cpp2
-rw-r--r--framework/domain/messageparser.cpp3
-rw-r--r--framework/domain/settings/accountsettings.cpp133
9 files changed, 129 insertions, 124 deletions
diff --git a/framework/domain/accountfactory.cpp b/framework/domain/accountfactory.cpp
index 10f01f65..182a0a1d 100644
--- a/framework/domain/accountfactory.cpp
+++ b/framework/domain/accountfactory.cpp
@@ -43,8 +43,8 @@ QString AccountFactory::name() const
43void AccountFactory::setAccountId(const QString &accountId) 43void AccountFactory::setAccountId(const QString &accountId)
44{ 44{
45 mAccountId = accountId; 45 mAccountId = accountId;
46 Sink::Store::fetchOne<Sink::ApplicationDomain::SinkAccount>(Sink::Query::IdentityFilter(accountId.toUtf8())) 46 Sink::Store::fetchOne<Sink::ApplicationDomain::SinkAccount>(Sink::Query().filter(accountId.toUtf8()))
47 .then<void, Sink::ApplicationDomain::SinkAccount>([this](const Sink::ApplicationDomain::SinkAccount &account) { 47 .syncThen<void, Sink::ApplicationDomain::SinkAccount>([this](const Sink::ApplicationDomain::SinkAccount &account) {
48 mAccountType = account.getProperty("type").toByteArray(); 48 mAccountType = account.getProperty("type").toByteArray();
49 loadPackage(); 49 loadPackage();
50 }).exec(); 50 }).exec();
diff --git a/framework/domain/accountscontroller.cpp b/framework/domain/accountscontroller.cpp
index 2f47fa03..5cb60d0c 100644
--- a/framework/domain/accountscontroller.cpp
+++ b/framework/domain/accountscontroller.cpp
@@ -34,9 +34,9 @@ void AccountsController::createAccount(const QString &accountType)
34{ 34{
35 auto account = Sink::ApplicationDomain::ApplicationDomainType::createEntity<Sink::ApplicationDomain::SinkAccount>(); 35 auto account = Sink::ApplicationDomain::ApplicationDomainType::createEntity<Sink::ApplicationDomain::SinkAccount>();
36 account.setProperty("type", accountType); 36 account.setProperty("type", accountType);
37 Sink::Store::create(account).then<void>([]() {}, 37 Sink::Store::create(account).syncThen<void>([](const KAsync::Error &error) {
38 [](int errorCode, const QString &errorMessage) { 38 if (error) {
39 qWarning() << "Error while creating account: " << errorMessage; 39 qWarning() << "Error while creating account: " << error.errorMessage;
40 }) 40 }
41 .exec(); 41 }).exec();
42} 42}
diff --git a/framework/domain/actions/sinkactions.cpp b/framework/domain/actions/sinkactions.cpp
index 921fe748..cc8d324e 100644
--- a/framework/domain/actions/sinkactions.cpp
+++ b/framework/domain/actions/sinkactions.cpp
@@ -28,20 +28,22 @@
28SINK_DEBUG_AREA("sinkactions") 28SINK_DEBUG_AREA("sinkactions")
29 29
30using namespace Kube; 30using namespace Kube;
31using namespace Sink;
32using namespace Sink::ApplicationDomain;
31 33
32static ActionHandlerHelper markAsReadHandler("org.kde.kube.actions.mark-as-read", 34static ActionHandlerHelper markAsReadHandler("org.kde.kube.actions.mark-as-read",
33 [](Context *context) -> bool { 35 [](Context *context) -> bool {
34 return context->property("mail").isValid(); 36 return context->property("mail").isValid();
35 }, 37 },
36 [](Context *context) { 38 [](Context *context) {
37 auto mail = context->property("mail").value<Sink::ApplicationDomain::Mail::Ptr>(); 39 auto mail = context->property("mail").value<Mail::Ptr>();
38 if (!mail) { 40 if (!mail) {
39 SinkWarning() << "Failed to get the mail mail: " << context->property("mail"); 41 SinkWarning() << "Failed to get the mail mail: " << context->property("mail");
40 return; 42 return;
41 } 43 }
42 mail->setProperty("unread", false); 44 mail->setProperty("unread", false);
43 SinkLog() << "Mark as read " << mail->identifier(); 45 SinkLog() << "Mark as read " << mail->identifier();
44 Sink::Store::modify(*mail).exec(); 46 Store::modify(*mail).exec();
45 } 47 }
46); 48);
47 49
@@ -50,14 +52,14 @@ static ActionHandlerHelper moveToTrashHandler("org.kde.kube.actions.move-to-tras
50 return context->property("mail").isValid(); 52 return context->property("mail").isValid();
51 }, 53 },
52 [](Context *context) { 54 [](Context *context) {
53 auto mail = context->property("mail").value<Sink::ApplicationDomain::Mail::Ptr>(); 55 auto mail = context->property("mail").value<Mail::Ptr>();
54 if (!mail) { 56 if (!mail) {
55 SinkWarning() << "Failed to get the mail mail: " << context->property("mail"); 57 SinkWarning() << "Failed to get the mail mail: " << context->property("mail");
56 return; 58 return;
57 } 59 }
58 mail->setTrash(true); 60 mail->setTrash(true);
59 SinkLog() << "Move to trash " << mail->identifier(); 61 SinkLog() << "Move to trash " << mail->identifier();
60 Sink::Store::modify(*mail).exec(); 62 Store::modify(*mail).exec();
61 } 63 }
62); 64);
63 65
@@ -66,13 +68,13 @@ static ActionHandlerHelper deleteHandler("org.kde.kube.actions.delete",
66 return context->property("mail").isValid(); 68 return context->property("mail").isValid();
67 }, 69 },
68 [](Context *context) { 70 [](Context *context) {
69 auto mail = context->property("mail").value<Sink::ApplicationDomain::Mail::Ptr>(); 71 auto mail = context->property("mail").value<Mail::Ptr>();
70 if (!mail) { 72 if (!mail) {
71 SinkWarning() << "Failed to get the mail mail: " << context->property("mail"); 73 SinkWarning() << "Failed to get the mail mail: " << context->property("mail");
72 return; 74 return;
73 } 75 }
74 SinkLog() << "Remove " << mail->identifier(); 76 SinkLog() << "Remove " << mail->identifier();
75 Sink::Store::remove(*mail).exec(); 77 Store::remove(*mail).exec();
76 } 78 }
77); 79);
78 80
@@ -81,12 +83,12 @@ static ActionHandlerHelper synchronizeHandler("org.kde.kube.actions.synchronize"
81 return true; 83 return true;
82 }, 84 },
83 [](Context *context) { 85 [](Context *context) {
84 if (auto folder = context->property("folder").value<Sink::ApplicationDomain::Folder::Ptr>()) { 86 if (auto folder = context->property("folder").value<Folder::Ptr>()) {
85 SinkLog() << "Synchronizing resource " << folder->resourceInstanceIdentifier(); 87 SinkLog() << "Synchronizing resource " << folder->resourceInstanceIdentifier();
86 Sink::Store::synchronize(Sink::Query::ResourceFilter(folder->resourceInstanceIdentifier())).exec(); 88 Store::synchronize(Query().resourceFilter(folder->resourceInstanceIdentifier())).exec();
87 } else { 89 } else {
88 SinkLog() << "Synchronizing all"; 90 SinkLog() << "Synchronizing all";
89 Sink::Store::synchronize(Sink::Query()).exec(); 91 Store::synchronize(Query()).exec();
90 } 92 }
91 } 93 }
92); 94);
@@ -102,17 +104,17 @@ static ActionHandlerHelper sendMailHandler("org.kde.kube.actions.sendmail",
102 auto message = context->property("message").value<KMime::Message::Ptr>(); 104 auto message = context->property("message").value<KMime::Message::Ptr>();
103 SinkLog() << "Sending a mail: "; 105 SinkLog() << "Sending a mail: ";
104 106
105 Sink::Query query; 107 Query query;
106 query += Sink::Query::CapabilityFilter(Sink::ApplicationDomain::ResourceCapabilities::Mail::transport); 108 query.containsFilter<ApplicationDomain::SinkResource::Capabilities>(ApplicationDomain::ResourceCapabilities::Mail::transport);
107 query += Sink::Query::AccountFilter(accountId); 109 query.filter<SinkResource::Account>(accountId);
108 Sink::Store::fetchAll<Sink::ApplicationDomain::SinkResource>(query) 110 Store::fetchAll<ApplicationDomain::SinkResource>(query)
109 .then<void, KAsync::Job<void>, QList<Sink::ApplicationDomain::SinkResource::Ptr>>([=](const QList<Sink::ApplicationDomain::SinkResource::Ptr> &resources) -> KAsync::Job<void> { 111 .then<void, QList<ApplicationDomain::SinkResource::Ptr>>([=](const QList<ApplicationDomain::SinkResource::Ptr> &resources) -> KAsync::Job<void> {
110 if (!resources.isEmpty()) { 112 if (!resources.isEmpty()) {
111 auto resourceId = resources[0]->identifier(); 113 auto resourceId = resources[0]->identifier();
112 SinkTrace() << "Sending message via resource: " << resourceId; 114 SinkTrace() << "Sending message via resource: " << resourceId;
113 Sink::ApplicationDomain::Mail mail(resourceId); 115 Mail mail(resourceId);
114 mail.setBlobProperty("mimeMessage", message->encodedContent()); 116 mail.setBlobProperty("mimeMessage", message->encodedContent());
115 return Sink::Store::create(mail); 117 return Store::create(mail);
116 } 118 }
117 SinkWarning() << "Failed to find a mailtransport resource"; 119 SinkWarning() << "Failed to find a mailtransport resource";
118 return KAsync::error<void>(0, "Failed to find a MailTransport resource."); 120 return KAsync::error<void>(0, "Failed to find a MailTransport resource.");
@@ -127,30 +129,30 @@ static ActionHandlerHelper saveAsDraft("org.kde.kube.actions.save-as-draft",
127 return !accountId.isEmpty() && message; 129 return !accountId.isEmpty() && message;
128 }, 130 },
129 ActionHandlerHelper::JobHandler([](Context *context) -> KAsync::Job<void> { 131 ActionHandlerHelper::JobHandler([](Context *context) -> KAsync::Job<void> {
130 SinkWarning() << "executing save as draft"; 132 SinkLog() << "Executing the save-as-draft action";
131 const auto accountId = context->property("accountId").value<QByteArray>(); 133 const auto accountId = context->property("accountId").value<QByteArray>();
132 const auto message = context->property("message").value<KMime::Message::Ptr>(); 134 const auto message = context->property("message").value<KMime::Message::Ptr>();
133 auto existingMail = context->property("existingMail").value<Sink::ApplicationDomain::Mail>(); 135 auto existingMail = context->property("existingMail").value<Mail>();
134 if (!message) { 136 if (!message) {
135 SinkWarning() << "Failed to get the mail: " << context->property("mail"); 137 SinkWarning() << "Failed to get the mail: " << context->property("mail");
136 return KAsync::error<void>(1, "Failed to get the mail: " + context->property("mail").toString()); 138 return KAsync::error<void>(1, "Failed to get the mail: " + context->property("mail").toString());
137 } 139 }
138 140
139 if (existingMail.identifier().isEmpty()) { 141 if (existingMail.identifier().isEmpty()) {
140 Sink::Query query; 142 Query query;
141 query += Sink::Query::CapabilityFilter(Sink::ApplicationDomain::ResourceCapabilities::Mail::drafts); 143 query.containsFilter<SinkResource::Capabilities>(ApplicationDomain::ResourceCapabilities::Mail::drafts);
142 query += Sink::Query::AccountFilter(accountId); 144 query.filter<SinkResource::Account>(accountId);
143 return Sink::Store::fetchOne<Sink::ApplicationDomain::SinkResource>(query) 145 return Store::fetchOne<SinkResource>(query)
144 .then<void, KAsync::Job<void>, Sink::ApplicationDomain::SinkResource>([=](const Sink::ApplicationDomain::SinkResource &resource) -> KAsync::Job<void> { 146 .then<void, SinkResource>([=](const SinkResource &resource) -> KAsync::Job<void> {
145 Sink::ApplicationDomain::Mail mail(resource.identifier()); 147 Mail mail(resource.identifier());
146 mail.setProperty("draft", true); 148 mail.setDraft(true);
147 mail.setBlobProperty("mimeMessage", message->encodedContent()); 149 mail.setMimeMessage(message->encodedContent());
148 return Sink::Store::create(mail); 150 return Store::create(mail);
149 }); 151 });
150 } else { 152 } else {
151 SinkWarning() << "Modifying an existing mail" << existingMail.identifier(); 153 SinkWarning() << "Modifying an existing mail" << existingMail.identifier();
152 existingMail.setBlobProperty("mimeMessage", message->encodedContent()); 154 existingMail.setMimeMessage(message->encodedContent());
153 return Sink::Store::modify(existingMail); 155 return Store::modify(existingMail);
154 } 156 }
155 }) 157 })
156); 158);
diff --git a/framework/domain/composercontroller.cpp b/framework/domain/composercontroller.cpp
index 2dcf1bb1..b2ad7ecc 100644
--- a/framework/domain/composercontroller.cpp
+++ b/framework/domain/composercontroller.cpp
@@ -133,7 +133,7 @@ void ComposerController::loadMessage(const QVariant &message, bool loadAsDraft)
133{ 133{
134 Sink::Query query(*message.value<Sink::ApplicationDomain::Mail::Ptr>()); 134 Sink::Query query(*message.value<Sink::ApplicationDomain::Mail::Ptr>());
135 query.request<Sink::ApplicationDomain::Mail::MimeMessage>(); 135 query.request<Sink::ApplicationDomain::Mail::MimeMessage>();
136 Sink::Store::fetchOne<Sink::ApplicationDomain::Mail>(query).then<void, Sink::ApplicationDomain::Mail>([this, loadAsDraft](const Sink::ApplicationDomain::Mail &mail) { 136 Sink::Store::fetchOne<Sink::ApplicationDomain::Mail>(query).syncThen<void, Sink::ApplicationDomain::Mail>([this, loadAsDraft](const Sink::ApplicationDomain::Mail &mail) {
137 m_existingMail = mail; 137 m_existingMail = mail;
138 const auto mailData = KMime::CRLFtoLF(mail.getMimeMessage()); 138 const auto mailData = KMime::CRLFtoLF(mail.getMimeMessage());
139 if (!mailData.isEmpty()) { 139 if (!mailData.isEmpty()) {
diff --git a/framework/domain/folderlistmodel.cpp b/framework/domain/folderlistmodel.cpp
index 14d3d5a7..7cf5ad5d 100644
--- a/framework/domain/folderlistmodel.cpp
+++ b/framework/domain/folderlistmodel.cpp
@@ -22,11 +22,14 @@
22#include <sink/store.h> 22#include <sink/store.h>
23#include <settings/settings.h> 23#include <settings/settings.h>
24 24
25using namespace Sink;
26using namespace Sink::ApplicationDomain;
27
25FolderListModel::FolderListModel(QObject *parent) : QIdentityProxyModel() 28FolderListModel::FolderListModel(QObject *parent) : QIdentityProxyModel()
26{ 29{
27 Sink::Query query; 30 Query query;
28 query.liveQuery = true; 31 query.liveQuery = true;
29 query.requestedProperties << "name" << "icon" << "parent"; 32 query.request<Folder::Name>().request<Folder::Icon>().request<Folder::Parent>();
30 query.parentProperty = "parent"; 33 query.parentProperty = "parent";
31 runQuery(query); 34 runQuery(query);
32} 35}
@@ -57,34 +60,32 @@ QVariant FolderListModel::data(const QModelIndex &idx, int role) const
57 case Icon: 60 case Icon:
58 return srcIdx.sibling(srcIdx.row(), 1).data(Qt::DisplayRole).toString(); 61 return srcIdx.sibling(srcIdx.row(), 1).data(Qt::DisplayRole).toString();
59 case Id: 62 case Id:
60 return srcIdx.data(Sink::Store::DomainObjectBaseRole).value<Sink::ApplicationDomain::ApplicationDomainType::Ptr>()->identifier(); 63 return srcIdx.data(Store::DomainObjectBaseRole).value<ApplicationDomainType::Ptr>()->identifier();
61 case DomainObject: 64 case DomainObject:
62 return srcIdx.data(Sink::Store::DomainObjectRole); 65 return srcIdx.data(Store::DomainObjectRole);
63 } 66 }
64 return QIdentityProxyModel::data(idx, role); 67 return QIdentityProxyModel::data(idx, role);
65} 68}
66 69
67void FolderListModel::runQuery(const Sink::Query &query) 70void FolderListModel::runQuery(const Query &query)
68{ 71{
69 mModel = Sink::Store::loadModel<Sink::ApplicationDomain::Folder>(query); 72 mModel = Store::loadModel<Folder>(query);
70 setSourceModel(mModel.data()); 73 setSourceModel(mModel.data());
71} 74}
72 75
73void FolderListModel::setAccountId(const QVariant &accountId) 76void FolderListModel::setAccountId(const QVariant &accountId)
74{ 77{
75 const auto account = accountId.toString().toUtf8(); 78 const auto account = accountId.toString().toUtf8();
76 Sink::Store::fetchAll<Sink::ApplicationDomain::SinkResource>(Sink::Query::PropertyFilter("account", QVariant::fromValue(account))) 79
77 .then<void, QList<Sink::ApplicationDomain::SinkResource::Ptr>>([this, account](const QList<Sink::ApplicationDomain::SinkResource::Ptr> &resources) { 80 //Get all folders of an account
78 Sink::Query query; 81 auto query = Query();
79 query.liveQuery = true; 82 query.resourceFilter<SinkResource::Account>(account);
80 query.requestedProperties << "name" << "icon" << "parent"; 83 query.liveQuery = true;
81 query.parentProperty = "parent"; 84 query.request<Folder::Name>()
82 for (const auto &r : resources) { 85 .request<Folder::Icon>()
83 qDebug() << "Found resources for account: " << r->identifier() << account; 86 .request<Folder::Parent>();
84 query.resources << r->identifier(); 87 query.parentProperty = Folder::Parent::name;
85 } 88 runQuery(query);
86 runQuery(query);
87 }).exec();
88} 89}
89 90
90QVariant FolderListModel::accountId() const 91QVariant FolderListModel::accountId() const
diff --git a/framework/domain/identitiesmodel.cpp b/framework/domain/identitiesmodel.cpp
index adb5d625..1958d2f5 100644
--- a/framework/domain/identitiesmodel.cpp
+++ b/framework/domain/identitiesmodel.cpp
@@ -83,7 +83,7 @@ void IdentitiesModel::runQuery(const Sink::Query &query)
83 setSourceModel(mModel.data()); 83 setSourceModel(mModel.data());
84 84
85 Sink::Store::fetchAll<Sink::ApplicationDomain::SinkAccount>(Sink::Query()) 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) { 86 .syncThen<void, QList<Sink::ApplicationDomain::SinkAccount::Ptr> >([this](const QList<Sink::ApplicationDomain::SinkAccount::Ptr> &accounts) {
87 for (const auto &account : accounts) { 87 for (const auto &account : accounts) {
88 mAccountNames.insert(account->identifier(), account->getProperty("name").toString()); 88 mAccountNames.insert(account->identifier(), account->getProperty("name").toString());
89 mAccountIcons.insert(account->identifier(), account->getProperty("icon").toString()); 89 mAccountIcons.insert(account->identifier(), account->getProperty("icon").toString());
diff --git a/framework/domain/maillistmodel.cpp b/framework/domain/maillistmodel.cpp
index e3f555c4..9afb6408 100644
--- a/framework/domain/maillistmodel.cpp
+++ b/framework/domain/maillistmodel.cpp
@@ -107,7 +107,7 @@ void MailListModel::setParentFolder(const QVariant &parentFolder)
107 } 107 }
108 Sink::Query query; 108 Sink::Query query;
109 query.liveQuery = true; 109 query.liveQuery = true;
110 query.resources << folder->resourceInstanceIdentifier(); 110 query.resourceFilter(folder->resourceInstanceIdentifier());
111 query.sort<Mail::Date>(); 111 query.sort<Mail::Date>();
112 query.limit = 100; 112 query.limit = 100;
113 query.request<Mail::Subject>(); 113 query.request<Mail::Subject>();
diff --git a/framework/domain/messageparser.cpp b/framework/domain/messageparser.cpp
index 262be0b7..febd1363 100644
--- a/framework/domain/messageparser.cpp
+++ b/framework/domain/messageparser.cpp
@@ -101,7 +101,8 @@ QVariant PartModel::data(const QModelIndex &index, int role) const
101 case Type: 101 case Type:
102 return part->metaObject()->className(); 102 return part->metaObject()->className();
103 case IsHidden: 103 case IsHidden:
104 return part->property("isHidden").toBool(); 104 return false;
105 //return part->property("isHidden").toBool();
105 106
106 } 107 }
107 } 108 }
diff --git a/framework/domain/settings/accountsettings.cpp b/framework/domain/settings/accountsettings.cpp
index cf348f39..ea798a73 100644
--- a/framework/domain/settings/accountsettings.cpp
+++ b/framework/domain/settings/accountsettings.cpp
@@ -23,6 +23,9 @@
23#include <QDir> 23#include <QDir>
24#include <QUrl> 24#include <QUrl>
25 25
26using namespace Sink;
27using namespace Sink::ApplicationDomain;
28
26AccountSettings::AccountSettings(QObject *parent) 29AccountSettings::AccountSettings(QObject *parent)
27 : QObject(parent) 30 : QObject(parent)
28{ 31{
@@ -130,87 +133,83 @@ void AccountSettings::saveAccount()
130{ 133{
131 qDebug() << "Saving account " << mAccountIdentifier << mMailtransportIdentifier; 134 qDebug() << "Saving account " << mAccountIdentifier << mMailtransportIdentifier;
132 Q_ASSERT(!mAccountIdentifier.isEmpty()); 135 Q_ASSERT(!mAccountIdentifier.isEmpty());
133 Sink::ApplicationDomain::SinkAccount account(mAccountIdentifier); 136 SinkAccount account(mAccountIdentifier);
134 account.setProperty("type", "imap"); 137 account.setAccountType("imap");
135 account.setProperty("name", mName); 138 account.setName(mName);
136 account.setProperty("icon", mIcon); 139 account.setIcon(mIcon);
137 Q_ASSERT(!account.identifier().isEmpty()); 140 Q_ASSERT(!account.identifier().isEmpty());
138 Sink::Store::modify(account).then<void>([]() {}, 141 Store::modify(account)
139 [](int errorCode, const QString &errorMessage) { 142 .onError([](const KAsync::Error &error) {
140 qWarning() << "Error while creating account: " << errorMessage; 143 qWarning() << "Error while creating account: " << error.errorMessage;;
141 }) 144 })
142 .exec(); 145 .exec();
143} 146}
144 147
145void AccountSettings::loadAccount() 148void AccountSettings::loadAccount()
146{ 149{
147 Q_ASSERT(!mAccountIdentifier.isEmpty()); 150 Q_ASSERT(!mAccountIdentifier.isEmpty());
148 Sink::Store::fetchOne<Sink::ApplicationDomain::SinkAccount>(Sink::Query::IdentityFilter(mAccountIdentifier)) 151 Store::fetchOne<SinkAccount>(Query().filter(mAccountIdentifier))
149 .then<void, Sink::ApplicationDomain::SinkAccount>([this](const Sink::ApplicationDomain::SinkAccount &account) { 152 .syncThen<void, SinkAccount>([this](const SinkAccount &account) {
150 mIcon = account.getProperty("icon").toString(); 153 mIcon = account.getIcon();
151 mName = account.getProperty("name").toString(); 154 mName = account.getName();
152 emit changed(); 155 emit changed();
153 }).exec(); 156 }).exec();
154} 157}
155 158
156void AccountSettings::loadImapResource() 159void AccountSettings::loadImapResource()
157{ 160{
158 Sink::Store::fetchOne<Sink::ApplicationDomain::SinkResource>(Sink::Query::AccountFilter(mAccountIdentifier) + Sink::Query::CapabilityFilter(Sink::ApplicationDomain::ResourceCapabilities::Mail::storage)) 161 Store::fetchOne<SinkResource>(Query().filter<SinkResource::Account>(mAccountIdentifier).containsFilter<SinkResource::Capabilities>(ResourceCapabilities::Mail::storage))
159 .then<void, Sink::ApplicationDomain::SinkResource>([this](const Sink::ApplicationDomain::SinkResource &resource) { 162 .syncThen<void, SinkResource>([this](const SinkResource &resource) {
160 mImapIdentifier = resource.identifier(); 163 mImapIdentifier = resource.identifier();
161 mImapServer = resource.getProperty("server").toString(); 164 mImapServer = resource.getProperty("server").toString();
162 mImapUsername = resource.getProperty("username").toString(); 165 mImapUsername = resource.getProperty("username").toString();
163 mImapPassword = resource.getProperty("password").toString(); 166 mImapPassword = resource.getProperty("password").toString();
164 emit imapResourceChanged(); 167 emit imapResourceChanged();
165 }, 168 }).onError([](const KAsync::Error &error) {
166 [](int errorCode, const QString &errorMessage) { 169 qWarning() << "Failed to find the imap resource: " << error.errorMessage;
167 qWarning() << "Failed to find the imap resource: " << errorMessage;
168 }).exec(); 170 }).exec();
169} 171}
170 172
171void AccountSettings::loadMaildirResource() 173void AccountSettings::loadMaildirResource()
172{ 174{
173 Sink::Store::fetchOne<Sink::ApplicationDomain::SinkResource>(Sink::Query::AccountFilter(mAccountIdentifier) + Sink::Query::CapabilityFilter(Sink::ApplicationDomain::ResourceCapabilities::Mail::storage)) 175 Store::fetchOne<SinkResource>(Query().filter<SinkResource::Account>(mAccountIdentifier).containsFilter<SinkResource::Capabilities>(ResourceCapabilities::Mail::storage))
174 .then<void, Sink::ApplicationDomain::SinkResource>([this](const Sink::ApplicationDomain::SinkResource &resource) { 176 .syncThen<void, SinkResource>([this](const SinkResource &resource) {
175 mMaildirIdentifier = resource.identifier(); 177 mMaildirIdentifier = resource.identifier();
176 auto path = resource.getProperty("path").toString(); 178 auto path = resource.getProperty("path").toString();
177 if (mPath != path) { 179 if (mPath != path) {
178 mPath = path; 180 mPath = path;
179 emit pathChanged(); 181 emit pathChanged();
180 } 182 }
181 }, 183 }).onError([](const KAsync::Error &error) {
182 [](int errorCode, const QString &errorMessage) { 184 qWarning() << "Failed to find the maildir resource: " << error.errorMessage;
183 qWarning() << "Failed to find the maildir resource: " << errorMessage;
184 }).exec(); 185 }).exec();
185} 186}
186 187
187void AccountSettings::loadMailtransportResource() 188void AccountSettings::loadMailtransportResource()
188{ 189{
189 Sink::Store::fetchOne<Sink::ApplicationDomain::SinkResource>(Sink::Query::AccountFilter(mAccountIdentifier) + Sink::Query::CapabilityFilter(Sink::ApplicationDomain::ResourceCapabilities::Mail::transport)) 190 Store::fetchOne<SinkResource>(Query().filter<SinkResource::Account>(mAccountIdentifier).containsFilter<SinkResource::Capabilities>(ResourceCapabilities::Mail::transport))
190 .then<void, Sink::ApplicationDomain::SinkResource>([this](const Sink::ApplicationDomain::SinkResource &resource) { 191 .syncThen<void, SinkResource>([this](const SinkResource &resource) {
191 mMailtransportIdentifier = resource.identifier(); 192 mMailtransportIdentifier = resource.identifier();
192 mSmtpServer = resource.getProperty("server").toString(); 193 mSmtpServer = resource.getProperty("server").toString();
193 mSmtpUsername = resource.getProperty("username").toString(); 194 mSmtpUsername = resource.getProperty("username").toString();
194 mSmtpPassword = resource.getProperty("password").toString(); 195 mSmtpPassword = resource.getProperty("password").toString();
195 emit smtpResourceChanged(); 196 emit smtpResourceChanged();
196 }, 197 }).onError([](const KAsync::Error &error) {
197 [](int errorCode, const QString &errorMessage) { 198 qWarning() << "Failed to find the smtp resource: " << error.errorMessage;
198 qWarning() << "Failed to find the smtp resource: " << errorMessage;
199 }).exec(); 199 }).exec();
200} 200}
201 201
202void AccountSettings::loadIdentity() 202void AccountSettings::loadIdentity()
203{ 203{
204 //FIXME this assumes that we only ever have one identity per account 204 //FIXME this assumes that we only ever have one identity per account
205 Sink::Store::fetchOne<Sink::ApplicationDomain::Identity>(Sink::Query::AccountFilter(mAccountIdentifier)) 205 Store::fetchOne<Identity>(Query().filter<Identity::Account>(mAccountIdentifier))
206 .then<void, Sink::ApplicationDomain::Identity>([this](const Sink::ApplicationDomain::Identity &identity) { 206 .syncThen<void, Identity>([this](const Identity &identity) {
207 mIdentityIdentifier = identity.identifier(); 207 mIdentityIdentifier = identity.identifier();
208 mUsername = identity.getProperty("username").toString(); 208 mUsername = identity.getProperty("username").toString();
209 mEmailAddress = identity.getProperty("address").toString(); 209 mEmailAddress = identity.getProperty("address").toString();
210 emit identityChanged(); 210 emit identityChanged();
211 }, 211 }).onError([](const KAsync::Error &error) {
212 [](int errorCode, const QString &errorMessage) { 212 qWarning() << "Failed to find the identity resource: " << error.errorMessage;
213 qWarning() << "Failed to find the identity resource: " << errorMessage;
214 }).exec(); 213 }).exec();
215} 214}
216 215
@@ -220,25 +219,26 @@ template<typename ResourceType>
220static QByteArray saveResource(const QByteArray &accountIdentifier, const QByteArray &identifier, const std::map<QByteArray, QVariant> &properties) 219static QByteArray saveResource(const QByteArray &accountIdentifier, const QByteArray &identifier, const std::map<QByteArray, QVariant> &properties)
221{ 220{
222 if (!identifier.isEmpty()) { 221 if (!identifier.isEmpty()) {
223 Sink::ApplicationDomain::SinkResource resource(identifier); 222 SinkResource resource(identifier);
224 for (const auto &pair : properties) { 223 for (const auto &pair : properties) {
225 resource.setProperty(pair.first, pair.second); 224 resource.setProperty(pair.first, pair.second);
226 } 225 }
227 Sink::Store::modify(resource).then<void>([](){}, [](int errorCode, const QString &errorMessage) { 226 Store::modify(resource)
228 qWarning() << "Error while modifying resource: " << errorMessage; 227 .onError([](const KAsync::Error &error) {
229 }) 228 qWarning() << "Error while modifying resource: " << error.errorMessage;
230 .exec(); 229 })
230 .exec();
231 } else { 231 } else {
232 auto resource = ResourceType::create(accountIdentifier); 232 auto resource = ResourceType::create(accountIdentifier);
233 auto newIdentifier = resource.identifier(); 233 auto newIdentifier = resource.identifier();
234 for (const auto &pair : properties) { 234 for (const auto &pair : properties) {
235 resource.setProperty(pair.first, pair.second); 235 resource.setProperty(pair.first, pair.second);
236 } 236 }
237 Sink::Store::create(resource).template then<void>([]() {}, 237 Store::create(resource)
238 [](int errorCode, const QString &errorMessage) { 238 .onError([](const KAsync::Error &error) {
239 qWarning() << "Error while creating resource: " << errorMessage; 239 qWarning() << "Error while creating resource: " << error.errorMessage;
240 }) 240 })
241 .exec(); 241 .exec();
242 return newIdentifier; 242 return newIdentifier;
243 } 243 }
244 return identifier; 244 return identifier;
@@ -246,7 +246,7 @@ static QByteArray saveResource(const QByteArray &accountIdentifier, const QByteA
246 246
247void AccountSettings::saveImapResource() 247void AccountSettings::saveImapResource()
248{ 248{
249 mImapIdentifier = saveResource<Sink::ApplicationDomain::ImapResource>(mAccountIdentifier, mImapIdentifier, { 249 mImapIdentifier = saveResource<ImapResource>(mAccountIdentifier, mImapIdentifier, {
250 {"server", mImapServer}, 250 {"server", mImapServer},
251 {"username", mImapUsername}, 251 {"username", mImapUsername},
252 {"password", mImapPassword}, 252 {"password", mImapPassword},
@@ -255,14 +255,14 @@ void AccountSettings::saveImapResource()
255 255
256void AccountSettings::saveMaildirResource() 256void AccountSettings::saveMaildirResource()
257{ 257{
258 mMaildirIdentifier = saveResource<Sink::ApplicationDomain::MaildirResource>(mAccountIdentifier, mMaildirIdentifier, { 258 mMaildirIdentifier = saveResource<MaildirResource>(mAccountIdentifier, mMaildirIdentifier, {
259 {"path", mPath}, 259 {"path", mPath},
260 }); 260 });
261} 261}
262 262
263void AccountSettings::saveMailtransportResource() 263void AccountSettings::saveMailtransportResource()
264{ 264{
265 mMailtransportIdentifier = saveResource<Sink::ApplicationDomain::MailtransportResource>(mAccountIdentifier, mMailtransportIdentifier, { 265 mMailtransportIdentifier = saveResource<MailtransportResource>(mAccountIdentifier, mMailtransportIdentifier, {
266 {"server", mSmtpServer}, 266 {"server", mSmtpServer},
267 {"username", mSmtpUsername}, 267 {"username", mSmtpUsername},
268 {"password", mSmtpPassword}, 268 {"password", mSmtpPassword},
@@ -272,22 +272,23 @@ void AccountSettings::saveMailtransportResource()
272void AccountSettings::saveIdentity() 272void AccountSettings::saveIdentity()
273{ 273{
274 if (!mIdentityIdentifier.isEmpty()) { 274 if (!mIdentityIdentifier.isEmpty()) {
275 Sink::ApplicationDomain::Identity identity(mMailtransportIdentifier); 275 Identity identity(mMailtransportIdentifier);
276 identity.setProperty("username", mUsername); 276 identity.setProperty("username", mUsername);
277 identity.setProperty("address", mEmailAddress); 277 identity.setProperty("address", mEmailAddress);
278 Sink::Store::modify(identity).then<void>([](){}, [](int errorCode, const QString &errorMessage) { 278 Store::modify(identity)
279 qWarning() << "Error while modifying identity: " << errorMessage; 279 .onError([](const KAsync::Error &error) {
280 qWarning() << "Error while modifying identity: " << error.errorMessage;
280 }) 281 })
281 .exec(); 282 .exec();
282 } else { 283 } else {
283 auto identity = Sink::ApplicationDomain::ApplicationDomainType::createEntity<Sink::ApplicationDomain::Identity>(); 284 auto identity = ApplicationDomainType::createEntity<Identity>();
284 mIdentityIdentifier = identity.identifier(); 285 mIdentityIdentifier = identity.identifier();
285 identity.setProperty("account", mAccountIdentifier); 286 identity.setAccount(mAccountIdentifier);
286 identity.setProperty("username", mUsername); 287 identity.setProperty("username", mUsername);
287 identity.setProperty("address", mEmailAddress); 288 identity.setProperty("address", mEmailAddress);
288 Sink::Store::create(identity).then<void>([]() {}, 289 Store::create(identity)
289 [](int errorCode, const QString &errorMessage) { 290 .onError([](const KAsync::Error &error) {
290 qWarning() << "Error while creating identity: " << errorMessage; 291 qWarning() << "Error while creating identity: " << error.errorMessage;
291 }) 292 })
292 .exec(); 293 .exec();
293 } 294 }
@@ -298,10 +299,10 @@ void AccountSettings::removeResource(const QByteArray &identifier)
298 if (identifier.isEmpty()) { 299 if (identifier.isEmpty()) {
299 qWarning() << "We're missing an identifier"; 300 qWarning() << "We're missing an identifier";
300 } else { 301 } else {
301 Sink::ApplicationDomain::SinkResource resource("", identifier, 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); 302 SinkResource resource(identifier);
302 Sink::Store::remove(resource).template then<void>([]() {}, 303 Store::remove(resource)
303 [](int errorCode, const QString &errorMessage) { 304 .onError([](const KAsync::Error &error) {
304 qWarning() << "Error while removing resource: " << errorMessage; 305 qWarning() << "Error while removing resource: " << error.errorMessage;
305 }) 306 })
306 .exec(); 307 .exec();
307 } 308 }
@@ -312,10 +313,10 @@ void AccountSettings::removeAccount()
312 if (mAccountIdentifier.isEmpty()) { 313 if (mAccountIdentifier.isEmpty()) {
313 qWarning() << "We're missing an identifier"; 314 qWarning() << "We're missing an identifier";
314 } else { 315 } else {
315 Sink::ApplicationDomain::SinkAccount account("", mAccountIdentifier, 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); 316 SinkAccount account(mAccountIdentifier);
316 Sink::Store::remove(account).then<void>([]() {}, 317 Store::remove(account)
317 [](int errorCode, const QString &errorMessage) { 318 .onError([](const KAsync::Error &error) {
318 qWarning() << "Error while removing account: " << errorMessage; 319 qWarning() << "Error while removing account: " << error.errorMessage;
319 }) 320 })
320 .exec(); 321 .exec();
321 } 322 }
@@ -326,10 +327,10 @@ void AccountSettings::removeIdentity()
326 if (mIdentityIdentifier.isEmpty()) { 327 if (mIdentityIdentifier.isEmpty()) {
327 qWarning() << "We're missing an identifier"; 328 qWarning() << "We're missing an identifier";
328 } else { 329 } else {
329 Sink::ApplicationDomain::Identity identity("", mIdentityIdentifier, 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); 330 Identity identity(mIdentityIdentifier);
330 Sink::Store::remove(identity).then<void>([]() {}, 331 Store::remove(identity)
331 [](int errorCode, const QString &errorMessage) { 332 .onError([](const KAsync::Error &error) {
332 qWarning() << "Error while removing identity: " << errorMessage; 333 qWarning() << "Error while removing identity: " << error.errorMessage;
333 }) 334 })
334 .exec(); 335 .exec();
335 } 336 }