From eb1664326e69757b18abd5fef8d22c9a328a2d28 Mon Sep 17 00:00:00 2001 From: Michael Bohlender Date: Sun, 4 Sep 2016 15:15:58 +0200 Subject: able to show all mails and not segfault by random mails (tempfix) --- framework/domain/messageparser.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'framework/domain') diff --git a/framework/domain/messageparser.cpp b/framework/domain/messageparser.cpp index 8363e119..ff763aec 100644 --- a/framework/domain/messageparser.cpp +++ b/framework/domain/messageparser.cpp @@ -89,7 +89,8 @@ QVariant PartModel::data(const QModelIndex &index, int role) const case Type: return part->metaObject()->className(); case IsHidden: - return part->property("isHidden").toBool(); + return false; + //return part->property("isHidden").toBool(); } } -- cgit v1.2.3 From 98e17d6a8ecd46a9d6956d81f781b05e940387e4 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 15 Sep 2016 11:58:26 +0200 Subject: Adapt to KAsync changes. --- framework/domain/accountfactory.cpp | 2 +- framework/domain/accountscontroller.cpp | 10 +-- framework/domain/actions/sinkactions.cpp | 4 +- framework/domain/composercontroller.cpp | 2 +- framework/domain/folderlistmodel.cpp | 2 +- framework/domain/identitiesmodel.cpp | 2 +- framework/domain/settings/accountsettings.cpp | 88 +++++++++++++-------------- 7 files changed, 54 insertions(+), 56 deletions(-) (limited to 'framework/domain') diff --git a/framework/domain/accountfactory.cpp b/framework/domain/accountfactory.cpp index 10f01f65..6261eaf1 100644 --- a/framework/domain/accountfactory.cpp +++ b/framework/domain/accountfactory.cpp @@ -44,7 +44,7 @@ void AccountFactory::setAccountId(const QString &accountId) { mAccountId = accountId; Sink::Store::fetchOne(Sink::Query::IdentityFilter(accountId.toUtf8())) - .then([this](const Sink::ApplicationDomain::SinkAccount &account) { + .syncThen([this](const Sink::ApplicationDomain::SinkAccount &account) { mAccountType = account.getProperty("type").toByteArray(); loadPackage(); }).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) { auto account = Sink::ApplicationDomain::ApplicationDomainType::createEntity(); account.setProperty("type", accountType); - Sink::Store::create(account).then([]() {}, - [](int errorCode, const QString &errorMessage) { - qWarning() << "Error while creating account: " << errorMessage; - }) - .exec(); + Sink::Store::create(account).syncThen([](const KAsync::Error &error) { + if (error) { + qWarning() << "Error while creating account: " << error.errorMessage; + } + }).exec(); } diff --git a/framework/domain/actions/sinkactions.cpp b/framework/domain/actions/sinkactions.cpp index 921fe748..f8a4e9ff 100644 --- a/framework/domain/actions/sinkactions.cpp +++ b/framework/domain/actions/sinkactions.cpp @@ -106,7 +106,7 @@ static ActionHandlerHelper sendMailHandler("org.kde.kube.actions.sendmail", query += Sink::Query::CapabilityFilter(Sink::ApplicationDomain::ResourceCapabilities::Mail::transport); query += Sink::Query::AccountFilter(accountId); Sink::Store::fetchAll(query) - .then, QList>([=](const QList &resources) -> KAsync::Job { + .then>([=](const QList &resources) -> KAsync::Job { if (!resources.isEmpty()) { auto resourceId = resources[0]->identifier(); SinkTrace() << "Sending message via resource: " << resourceId; @@ -141,7 +141,7 @@ static ActionHandlerHelper saveAsDraft("org.kde.kube.actions.save-as-draft", query += Sink::Query::CapabilityFilter(Sink::ApplicationDomain::ResourceCapabilities::Mail::drafts); query += Sink::Query::AccountFilter(accountId); return Sink::Store::fetchOne(query) - .then, Sink::ApplicationDomain::SinkResource>([=](const Sink::ApplicationDomain::SinkResource &resource) -> KAsync::Job { + .then([=](const Sink::ApplicationDomain::SinkResource &resource) -> KAsync::Job { Sink::ApplicationDomain::Mail mail(resource.identifier()); mail.setProperty("draft", true); mail.setBlobProperty("mimeMessage", message->encodedContent()); 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) { Sink::Query query(*message.value()); query.request(); - Sink::Store::fetchOne(query).then([this, loadAsDraft](const Sink::ApplicationDomain::Mail &mail) { + Sink::Store::fetchOne(query).syncThen([this, loadAsDraft](const Sink::ApplicationDomain::Mail &mail) { m_existingMail = mail; const auto mailData = KMime::CRLFtoLF(mail.getMimeMessage()); if (!mailData.isEmpty()) { diff --git a/framework/domain/folderlistmodel.cpp b/framework/domain/folderlistmodel.cpp index 14d3d5a7..000dd263 100644 --- a/framework/domain/folderlistmodel.cpp +++ b/framework/domain/folderlistmodel.cpp @@ -74,7 +74,7 @@ void FolderListModel::setAccountId(const QVariant &accountId) { const auto account = accountId.toString().toUtf8(); Sink::Store::fetchAll(Sink::Query::PropertyFilter("account", QVariant::fromValue(account))) - .then>([this, account](const QList &resources) { + .syncThen>([this, account](const QList &resources) { Sink::Query query; query.liveQuery = true; query.requestedProperties << "name" << "icon" << "parent"; 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) setSourceModel(mModel.data()); Sink::Store::fetchAll(Sink::Query()) - .then >([this](const QList &accounts) { + .syncThen >([this](const QList &accounts) { for (const auto &account : accounts) { mAccountNames.insert(account->identifier(), account->getProperty("name").toString()); mAccountIcons.insert(account->identifier(), account->getProperty("icon").toString()); diff --git a/framework/domain/settings/accountsettings.cpp b/framework/domain/settings/accountsettings.cpp index cf348f39..9a3be059 100644 --- a/framework/domain/settings/accountsettings.cpp +++ b/framework/domain/settings/accountsettings.cpp @@ -135,18 +135,18 @@ void AccountSettings::saveAccount() account.setProperty("name", mName); account.setProperty("icon", mIcon); Q_ASSERT(!account.identifier().isEmpty()); - Sink::Store::modify(account).then([]() {}, - [](int errorCode, const QString &errorMessage) { - qWarning() << "Error while creating account: " << errorMessage; - }) - .exec(); + Sink::Store::modify(account) + .onError([](const KAsync::Error &error) { + qWarning() << "Error while creating account: " << error.errorMessage;; + }) + .exec(); } void AccountSettings::loadAccount() { Q_ASSERT(!mAccountIdentifier.isEmpty()); Sink::Store::fetchOne(Sink::Query::IdentityFilter(mAccountIdentifier)) - .then([this](const Sink::ApplicationDomain::SinkAccount &account) { + .syncThen([this](const Sink::ApplicationDomain::SinkAccount &account) { mIcon = account.getProperty("icon").toString(); mName = account.getProperty("name").toString(); emit changed(); @@ -156,46 +156,43 @@ void AccountSettings::loadAccount() void AccountSettings::loadImapResource() { Sink::Store::fetchOne(Sink::Query::AccountFilter(mAccountIdentifier) + Sink::Query::CapabilityFilter(Sink::ApplicationDomain::ResourceCapabilities::Mail::storage)) - .then([this](const Sink::ApplicationDomain::SinkResource &resource) { + .syncThen([this](const Sink::ApplicationDomain::SinkResource &resource) { mImapIdentifier = resource.identifier(); mImapServer = resource.getProperty("server").toString(); mImapUsername = resource.getProperty("username").toString(); mImapPassword = resource.getProperty("password").toString(); emit imapResourceChanged(); - }, - [](int errorCode, const QString &errorMessage) { - qWarning() << "Failed to find the imap resource: " << errorMessage; + }).onError([](const KAsync::Error &error) { + qWarning() << "Failed to find the imap resource: " << error.errorMessage; }).exec(); } void AccountSettings::loadMaildirResource() { Sink::Store::fetchOne(Sink::Query::AccountFilter(mAccountIdentifier) + Sink::Query::CapabilityFilter(Sink::ApplicationDomain::ResourceCapabilities::Mail::storage)) - .then([this](const Sink::ApplicationDomain::SinkResource &resource) { + .syncThen([this](const Sink::ApplicationDomain::SinkResource &resource) { mMaildirIdentifier = resource.identifier(); auto path = resource.getProperty("path").toString(); if (mPath != path) { mPath = path; emit pathChanged(); } - }, - [](int errorCode, const QString &errorMessage) { - qWarning() << "Failed to find the maildir resource: " << errorMessage; + }).onError([](const KAsync::Error &error) { + qWarning() << "Failed to find the maildir resource: " << error.errorMessage; }).exec(); } void AccountSettings::loadMailtransportResource() { Sink::Store::fetchOne(Sink::Query::AccountFilter(mAccountIdentifier) + Sink::Query::CapabilityFilter(Sink::ApplicationDomain::ResourceCapabilities::Mail::transport)) - .then([this](const Sink::ApplicationDomain::SinkResource &resource) { + .syncThen([this](const Sink::ApplicationDomain::SinkResource &resource) { mMailtransportIdentifier = resource.identifier(); mSmtpServer = resource.getProperty("server").toString(); mSmtpUsername = resource.getProperty("username").toString(); mSmtpPassword = resource.getProperty("password").toString(); emit smtpResourceChanged(); - }, - [](int errorCode, const QString &errorMessage) { - qWarning() << "Failed to find the smtp resource: " << errorMessage; + }).onError([](const KAsync::Error &error) { + qWarning() << "Failed to find the smtp resource: " << error.errorMessage; }).exec(); } @@ -203,14 +200,13 @@ void AccountSettings::loadIdentity() { //FIXME this assumes that we only ever have one identity per account Sink::Store::fetchOne(Sink::Query::AccountFilter(mAccountIdentifier)) - .then([this](const Sink::ApplicationDomain::Identity &identity) { + .syncThen([this](const Sink::ApplicationDomain::Identity &identity) { mIdentityIdentifier = identity.identifier(); mUsername = identity.getProperty("username").toString(); mEmailAddress = identity.getProperty("address").toString(); emit identityChanged(); - }, - [](int errorCode, const QString &errorMessage) { - qWarning() << "Failed to find the identity resource: " << errorMessage; + }).onError([](const KAsync::Error &error) { + qWarning() << "Failed to find the identity resource: " << error.errorMessage; }).exec(); } @@ -224,21 +220,22 @@ static QByteArray saveResource(const QByteArray &accountIdentifier, const QByteA for (const auto &pair : properties) { resource.setProperty(pair.first, pair.second); } - Sink::Store::modify(resource).then([](){}, [](int errorCode, const QString &errorMessage) { - qWarning() << "Error while modifying resource: " << errorMessage; - }) - .exec(); + Sink::Store::modify(resource) + .onError([](const KAsync::Error &error) { + qWarning() << "Error while modifying resource: " << error.errorMessage; + }) + .exec(); } else { auto resource = ResourceType::create(accountIdentifier); auto newIdentifier = resource.identifier(); for (const auto &pair : properties) { resource.setProperty(pair.first, pair.second); } - Sink::Store::create(resource).template then([]() {}, - [](int errorCode, const QString &errorMessage) { - qWarning() << "Error while creating resource: " << errorMessage; - }) - .exec(); + Sink::Store::create(resource) + .onError([](const KAsync::Error &error) { + qWarning() << "Error while creating resource: " << error.errorMessage; + }) + .exec(); return newIdentifier; } return identifier; @@ -275,8 +272,9 @@ void AccountSettings::saveIdentity() Sink::ApplicationDomain::Identity identity(mMailtransportIdentifier); identity.setProperty("username", mUsername); identity.setProperty("address", mEmailAddress); - Sink::Store::modify(identity).then([](){}, [](int errorCode, const QString &errorMessage) { - qWarning() << "Error while modifying identity: " << errorMessage; + Sink::Store::modify(identity) + .onError([](const KAsync::Error &error) { + qWarning() << "Error while modifying identity: " << error.errorMessage; }) .exec(); } else { @@ -285,9 +283,9 @@ void AccountSettings::saveIdentity() identity.setProperty("account", mAccountIdentifier); identity.setProperty("username", mUsername); identity.setProperty("address", mEmailAddress); - Sink::Store::create(identity).then([]() {}, - [](int errorCode, const QString &errorMessage) { - qWarning() << "Error while creating identity: " << errorMessage; + Sink::Store::create(identity) + .onError([](const KAsync::Error &error) { + qWarning() << "Error while creating identity: " << error.errorMessage; }) .exec(); } @@ -299,9 +297,9 @@ void AccountSettings::removeResource(const QByteArray &identifier) qWarning() << "We're missing an identifier"; } else { Sink::ApplicationDomain::SinkResource resource("", identifier, 0, QSharedPointer::create()); - Sink::Store::remove(resource).template then([]() {}, - [](int errorCode, const QString &errorMessage) { - qWarning() << "Error while removing resource: " << errorMessage; + Sink::Store::remove(resource) + .onError([](const KAsync::Error &error) { + qWarning() << "Error while removing resource: " << error.errorMessage; }) .exec(); } @@ -313,9 +311,9 @@ void AccountSettings::removeAccount() qWarning() << "We're missing an identifier"; } else { Sink::ApplicationDomain::SinkAccount account("", mAccountIdentifier, 0, QSharedPointer::create()); - Sink::Store::remove(account).then([]() {}, - [](int errorCode, const QString &errorMessage) { - qWarning() << "Error while removing account: " << errorMessage; + Sink::Store::remove(account) + .onError([](const KAsync::Error &error) { + qWarning() << "Error while removing account: " << error.errorMessage; }) .exec(); } @@ -327,9 +325,9 @@ void AccountSettings::removeIdentity() qWarning() << "We're missing an identifier"; } else { Sink::ApplicationDomain::Identity identity("", mIdentityIdentifier, 0, QSharedPointer::create()); - Sink::Store::remove(identity).then([]() {}, - [](int errorCode, const QString &errorMessage) { - qWarning() << "Error while removing identity: " << errorMessage; + Sink::Store::remove(identity) + .onError([](const KAsync::Error &error) { + qWarning() << "Error while removing identity: " << error.errorMessage; }) .exec(); } -- cgit v1.2.3 From dd060cc5e3b336a77f8e5e76df4bc76a58e22cd4 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 4 Oct 2016 12:10:06 +0200 Subject: Adapted to new query api --- framework/domain/actions/sinkactions.cpp | 15 ++++++++------- framework/domain/folderlistmodel.cpp | 23 +++++++++++------------ framework/domain/settings/accountsettings.cpp | 8 ++++---- 3 files changed, 23 insertions(+), 23 deletions(-) (limited to 'framework/domain') diff --git a/framework/domain/actions/sinkactions.cpp b/framework/domain/actions/sinkactions.cpp index f8a4e9ff..47041a5b 100644 --- a/framework/domain/actions/sinkactions.cpp +++ b/framework/domain/actions/sinkactions.cpp @@ -28,6 +28,7 @@ SINK_DEBUG_AREA("sinkactions") using namespace Kube; +using namespace Sink; static ActionHandlerHelper markAsReadHandler("org.kde.kube.actions.mark-as-read", [](Context *context) -> bool { @@ -102,11 +103,11 @@ static ActionHandlerHelper sendMailHandler("org.kde.kube.actions.sendmail", auto message = context->property("message").value(); SinkLog() << "Sending a mail: "; - Sink::Query query; - query += Sink::Query::CapabilityFilter(Sink::ApplicationDomain::ResourceCapabilities::Mail::transport); - query += Sink::Query::AccountFilter(accountId); - Sink::Store::fetchAll(query) - .then>([=](const QList &resources) -> KAsync::Job { + Query query; + query.containsFilter(ApplicationDomain::ResourceCapabilities::Mail::transport); + query.filter(ApplicationDomain::SinkAccount(accountId)); + Store::fetchAll(query) + .then>([=](const QList &resources) -> KAsync::Job { if (!resources.isEmpty()) { auto resourceId = resources[0]->identifier(); SinkTrace() << "Sending message via resource: " << resourceId; @@ -138,8 +139,8 @@ static ActionHandlerHelper saveAsDraft("org.kde.kube.actions.save-as-draft", if (existingMail.identifier().isEmpty()) { Sink::Query query; - query += Sink::Query::CapabilityFilter(Sink::ApplicationDomain::ResourceCapabilities::Mail::drafts); - query += Sink::Query::AccountFilter(accountId); + query.containsFilter(ApplicationDomain::ResourceCapabilities::Mail::drafts); + query.filter(ApplicationDomain::SinkAccount(accountId)); return Sink::Store::fetchOne(query) .then([=](const Sink::ApplicationDomain::SinkResource &resource) -> KAsync::Job { Sink::ApplicationDomain::Mail mail(resource.identifier()); diff --git a/framework/domain/folderlistmodel.cpp b/framework/domain/folderlistmodel.cpp index 000dd263..98453ce9 100644 --- a/framework/domain/folderlistmodel.cpp +++ b/framework/domain/folderlistmodel.cpp @@ -72,19 +72,18 @@ void FolderListModel::runQuery(const Sink::Query &query) void FolderListModel::setAccountId(const QVariant &accountId) { + using namespace Sink::ApplicationDomain; const auto account = accountId.toString().toUtf8(); - Sink::Store::fetchAll(Sink::Query::PropertyFilter("account", QVariant::fromValue(account))) - .syncThen>([this, account](const QList &resources) { - Sink::Query query; - query.liveQuery = true; - query.requestedProperties << "name" << "icon" << "parent"; - query.parentProperty = "parent"; - for (const auto &r : resources) { - qDebug() << "Found resources for account: " << r->identifier() << account; - query.resources << r->identifier(); - } - runQuery(query); - }).exec(); + + //Get all folders of an account + auto query = Sink::Query(); + query.filter(SinkAccount(account)); + query.liveQuery = true; + query.request() + .request() + .request(); + query.parentProperty = Folder::Parent::name; + runQuery(query); } QVariant FolderListModel::accountId() const diff --git a/framework/domain/settings/accountsettings.cpp b/framework/domain/settings/accountsettings.cpp index 9a3be059..020fd503 100644 --- a/framework/domain/settings/accountsettings.cpp +++ b/framework/domain/settings/accountsettings.cpp @@ -155,7 +155,7 @@ void AccountSettings::loadAccount() void AccountSettings::loadImapResource() { - Sink::Store::fetchOne(Sink::Query::AccountFilter(mAccountIdentifier) + Sink::Query::CapabilityFilter(Sink::ApplicationDomain::ResourceCapabilities::Mail::storage)) + Sink::Store::fetchOne(Sink::Query().filter(Sink::ApplicationDomain::SinkAccount(mAccountIdentifier)).containsFilter(Sink::ApplicationDomain::ResourceCapabilities::Mail::storage)) .syncThen([this](const Sink::ApplicationDomain::SinkResource &resource) { mImapIdentifier = resource.identifier(); mImapServer = resource.getProperty("server").toString(); @@ -169,7 +169,7 @@ void AccountSettings::loadImapResource() void AccountSettings::loadMaildirResource() { - Sink::Store::fetchOne(Sink::Query::AccountFilter(mAccountIdentifier) + Sink::Query::CapabilityFilter(Sink::ApplicationDomain::ResourceCapabilities::Mail::storage)) + Sink::Store::fetchOne(Sink::Query().filter(Sink::ApplicationDomain::SinkAccount(mAccountIdentifier)).containsFilter(Sink::ApplicationDomain::ResourceCapabilities::Mail::storage)) .syncThen([this](const Sink::ApplicationDomain::SinkResource &resource) { mMaildirIdentifier = resource.identifier(); auto path = resource.getProperty("path").toString(); @@ -184,7 +184,7 @@ void AccountSettings::loadMaildirResource() void AccountSettings::loadMailtransportResource() { - Sink::Store::fetchOne(Sink::Query::AccountFilter(mAccountIdentifier) + Sink::Query::CapabilityFilter(Sink::ApplicationDomain::ResourceCapabilities::Mail::transport)) + Sink::Store::fetchOne(Sink::Query().filter(Sink::ApplicationDomain::SinkAccount(mAccountIdentifier)).containsFilter(Sink::ApplicationDomain::ResourceCapabilities::Mail::transport)) .syncThen([this](const Sink::ApplicationDomain::SinkResource &resource) { mMailtransportIdentifier = resource.identifier(); mSmtpServer = resource.getProperty("server").toString(); @@ -199,7 +199,7 @@ void AccountSettings::loadMailtransportResource() void AccountSettings::loadIdentity() { //FIXME this assumes that we only ever have one identity per account - Sink::Store::fetchOne(Sink::Query::AccountFilter(mAccountIdentifier)) + Sink::Store::fetchOne(Sink::Query().filter(Sink::ApplicationDomain::SinkAccount(mAccountIdentifier))) .syncThen([this](const Sink::ApplicationDomain::Identity &identity) { mIdentityIdentifier = identity.identifier(); mUsername = identity.getProperty("username").toString(); -- cgit v1.2.3 From 268eb7207b955bb92e4ae2572996877e7f837325 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 4 Oct 2016 12:19:27 +0200 Subject: Less namespaces improve readability --- framework/domain/actions/sinkactions.cpp | 37 +++++++++-------- framework/domain/folderlistmodel.cpp | 16 ++++---- framework/domain/settings/accountsettings.cpp | 59 ++++++++++++++------------- 3 files changed, 59 insertions(+), 53 deletions(-) (limited to 'framework/domain') diff --git a/framework/domain/actions/sinkactions.cpp b/framework/domain/actions/sinkactions.cpp index 47041a5b..e79e79c9 100644 --- a/framework/domain/actions/sinkactions.cpp +++ b/framework/domain/actions/sinkactions.cpp @@ -29,20 +29,21 @@ SINK_DEBUG_AREA("sinkactions") using namespace Kube; using namespace Sink; +using namespace Sink::ApplicationDomain; static ActionHandlerHelper markAsReadHandler("org.kde.kube.actions.mark-as-read", [](Context *context) -> bool { return context->property("mail").isValid(); }, [](Context *context) { - auto mail = context->property("mail").value(); + auto mail = context->property("mail").value(); if (!mail) { SinkWarning() << "Failed to get the mail mail: " << context->property("mail"); return; } mail->setProperty("unread", false); SinkLog() << "Mark as read " << mail->identifier(); - Sink::Store::modify(*mail).exec(); + Store::modify(*mail).exec(); } ); @@ -51,14 +52,14 @@ static ActionHandlerHelper moveToTrashHandler("org.kde.kube.actions.move-to-tras return context->property("mail").isValid(); }, [](Context *context) { - auto mail = context->property("mail").value(); + auto mail = context->property("mail").value(); if (!mail) { SinkWarning() << "Failed to get the mail mail: " << context->property("mail"); return; } mail->setTrash(true); SinkLog() << "Move to trash " << mail->identifier(); - Sink::Store::modify(*mail).exec(); + Store::modify(*mail).exec(); } ); @@ -67,13 +68,13 @@ static ActionHandlerHelper deleteHandler("org.kde.kube.actions.delete", return context->property("mail").isValid(); }, [](Context *context) { - auto mail = context->property("mail").value(); + auto mail = context->property("mail").value(); if (!mail) { SinkWarning() << "Failed to get the mail mail: " << context->property("mail"); return; } SinkLog() << "Remove " << mail->identifier(); - Sink::Store::remove(*mail).exec(); + Store::remove(*mail).exec(); } ); @@ -82,12 +83,12 @@ static ActionHandlerHelper synchronizeHandler("org.kde.kube.actions.synchronize" return true; }, [](Context *context) { - if (auto folder = context->property("folder").value()) { + if (auto folder = context->property("folder").value()) { SinkLog() << "Synchronizing resource " << folder->resourceInstanceIdentifier(); - Sink::Store::synchronize(Sink::Query::ResourceFilter(folder->resourceInstanceIdentifier())).exec(); + Store::synchronize(Query::ResourceFilter(folder->resourceInstanceIdentifier())).exec(); } else { SinkLog() << "Synchronizing all"; - Sink::Store::synchronize(Sink::Query()).exec(); + Store::synchronize(Query()).exec(); } } ); @@ -111,9 +112,9 @@ static ActionHandlerHelper sendMailHandler("org.kde.kube.actions.sendmail", if (!resources.isEmpty()) { auto resourceId = resources[0]->identifier(); SinkTrace() << "Sending message via resource: " << resourceId; - Sink::ApplicationDomain::Mail mail(resourceId); + Mail mail(resourceId); mail.setBlobProperty("mimeMessage", message->encodedContent()); - return Sink::Store::create(mail); + return Store::create(mail); } SinkWarning() << "Failed to find a mailtransport resource"; return KAsync::error(0, "Failed to find a MailTransport resource."); @@ -131,27 +132,27 @@ static ActionHandlerHelper saveAsDraft("org.kde.kube.actions.save-as-draft", SinkWarning() << "executing save as draft"; const auto accountId = context->property("accountId").value(); const auto message = context->property("message").value(); - auto existingMail = context->property("existingMail").value(); + auto existingMail = context->property("existingMail").value(); if (!message) { SinkWarning() << "Failed to get the mail: " << context->property("mail"); return KAsync::error(1, "Failed to get the mail: " + context->property("mail").toString()); } if (existingMail.identifier().isEmpty()) { - Sink::Query query; + Query query; query.containsFilter(ApplicationDomain::ResourceCapabilities::Mail::drafts); query.filter(ApplicationDomain::SinkAccount(accountId)); - return Sink::Store::fetchOne(query) - .then([=](const Sink::ApplicationDomain::SinkResource &resource) -> KAsync::Job { - Sink::ApplicationDomain::Mail mail(resource.identifier()); + return Store::fetchOne(query) + .then([=](const SinkResource &resource) -> KAsync::Job { + Mail mail(resource.identifier()); mail.setProperty("draft", true); mail.setBlobProperty("mimeMessage", message->encodedContent()); - return Sink::Store::create(mail); + return Store::create(mail); }); } else { SinkWarning() << "Modifying an existing mail" << existingMail.identifier(); existingMail.setBlobProperty("mimeMessage", message->encodedContent()); - return Sink::Store::modify(existingMail); + return Store::modify(existingMail); } }) ); diff --git a/framework/domain/folderlistmodel.cpp b/framework/domain/folderlistmodel.cpp index 98453ce9..e852288f 100644 --- a/framework/domain/folderlistmodel.cpp +++ b/framework/domain/folderlistmodel.cpp @@ -22,9 +22,12 @@ #include #include +using namespace Sink; +using namespace Sink::ApplicationDomain; + FolderListModel::FolderListModel(QObject *parent) : QIdentityProxyModel() { - Sink::Query query; + Query query; query.liveQuery = true; query.requestedProperties << "name" << "icon" << "parent"; query.parentProperty = "parent"; @@ -57,26 +60,25 @@ QVariant FolderListModel::data(const QModelIndex &idx, int role) const case Icon: return srcIdx.sibling(srcIdx.row(), 1).data(Qt::DisplayRole).toString(); case Id: - return srcIdx.data(Sink::Store::DomainObjectBaseRole).value()->identifier(); + return srcIdx.data(Store::DomainObjectBaseRole).value()->identifier(); case DomainObject: - return srcIdx.data(Sink::Store::DomainObjectRole); + return srcIdx.data(Store::DomainObjectRole); } return QIdentityProxyModel::data(idx, role); } -void FolderListModel::runQuery(const Sink::Query &query) +void FolderListModel::runQuery(const Query &query) { - mModel = Sink::Store::loadModel(query); + mModel = Store::loadModel(query); setSourceModel(mModel.data()); } void FolderListModel::setAccountId(const QVariant &accountId) { - using namespace Sink::ApplicationDomain; const auto account = accountId.toString().toUtf8(); //Get all folders of an account - auto query = Sink::Query(); + auto query = Query(); query.filter(SinkAccount(account)); query.liveQuery = true; query.request() diff --git a/framework/domain/settings/accountsettings.cpp b/framework/domain/settings/accountsettings.cpp index 020fd503..635aef6e 100644 --- a/framework/domain/settings/accountsettings.cpp +++ b/framework/domain/settings/accountsettings.cpp @@ -23,6 +23,9 @@ #include #include +using namespace Sink; +using namespace Sink::ApplicationDomain; + AccountSettings::AccountSettings(QObject *parent) : QObject(parent) { @@ -130,12 +133,12 @@ void AccountSettings::saveAccount() { qDebug() << "Saving account " << mAccountIdentifier << mMailtransportIdentifier; Q_ASSERT(!mAccountIdentifier.isEmpty()); - Sink::ApplicationDomain::SinkAccount account(mAccountIdentifier); + SinkAccount account(mAccountIdentifier); account.setProperty("type", "imap"); account.setProperty("name", mName); account.setProperty("icon", mIcon); Q_ASSERT(!account.identifier().isEmpty()); - Sink::Store::modify(account) + Store::modify(account) .onError([](const KAsync::Error &error) { qWarning() << "Error while creating account: " << error.errorMessage;; }) @@ -145,8 +148,8 @@ void AccountSettings::saveAccount() void AccountSettings::loadAccount() { Q_ASSERT(!mAccountIdentifier.isEmpty()); - Sink::Store::fetchOne(Sink::Query::IdentityFilter(mAccountIdentifier)) - .syncThen([this](const Sink::ApplicationDomain::SinkAccount &account) { + Store::fetchOne(Query::IdentityFilter(mAccountIdentifier)) + .syncThen([this](const SinkAccount &account) { mIcon = account.getProperty("icon").toString(); mName = account.getProperty("name").toString(); emit changed(); @@ -155,8 +158,8 @@ void AccountSettings::loadAccount() void AccountSettings::loadImapResource() { - Sink::Store::fetchOne(Sink::Query().filter(Sink::ApplicationDomain::SinkAccount(mAccountIdentifier)).containsFilter(Sink::ApplicationDomain::ResourceCapabilities::Mail::storage)) - .syncThen([this](const Sink::ApplicationDomain::SinkResource &resource) { + Store::fetchOne(Query().filter(SinkAccount(mAccountIdentifier)).containsFilter(ResourceCapabilities::Mail::storage)) + .syncThen([this](const SinkResource &resource) { mImapIdentifier = resource.identifier(); mImapServer = resource.getProperty("server").toString(); mImapUsername = resource.getProperty("username").toString(); @@ -169,8 +172,8 @@ void AccountSettings::loadImapResource() void AccountSettings::loadMaildirResource() { - Sink::Store::fetchOne(Sink::Query().filter(Sink::ApplicationDomain::SinkAccount(mAccountIdentifier)).containsFilter(Sink::ApplicationDomain::ResourceCapabilities::Mail::storage)) - .syncThen([this](const Sink::ApplicationDomain::SinkResource &resource) { + Store::fetchOne(Query().filter(SinkAccount(mAccountIdentifier)).containsFilter(ResourceCapabilities::Mail::storage)) + .syncThen([this](const SinkResource &resource) { mMaildirIdentifier = resource.identifier(); auto path = resource.getProperty("path").toString(); if (mPath != path) { @@ -184,8 +187,8 @@ void AccountSettings::loadMaildirResource() void AccountSettings::loadMailtransportResource() { - Sink::Store::fetchOne(Sink::Query().filter(Sink::ApplicationDomain::SinkAccount(mAccountIdentifier)).containsFilter(Sink::ApplicationDomain::ResourceCapabilities::Mail::transport)) - .syncThen([this](const Sink::ApplicationDomain::SinkResource &resource) { + Store::fetchOne(Query().filter(SinkAccount(mAccountIdentifier)).containsFilter(ResourceCapabilities::Mail::transport)) + .syncThen([this](const SinkResource &resource) { mMailtransportIdentifier = resource.identifier(); mSmtpServer = resource.getProperty("server").toString(); mSmtpUsername = resource.getProperty("username").toString(); @@ -199,8 +202,8 @@ void AccountSettings::loadMailtransportResource() void AccountSettings::loadIdentity() { //FIXME this assumes that we only ever have one identity per account - Sink::Store::fetchOne(Sink::Query().filter(Sink::ApplicationDomain::SinkAccount(mAccountIdentifier))) - .syncThen([this](const Sink::ApplicationDomain::Identity &identity) { + Store::fetchOne(Query().filter(SinkAccount(mAccountIdentifier))) + .syncThen([this](const Identity &identity) { mIdentityIdentifier = identity.identifier(); mUsername = identity.getProperty("username").toString(); mEmailAddress = identity.getProperty("address").toString(); @@ -216,11 +219,11 @@ template static QByteArray saveResource(const QByteArray &accountIdentifier, const QByteArray &identifier, const std::map &properties) { if (!identifier.isEmpty()) { - Sink::ApplicationDomain::SinkResource resource(identifier); + SinkResource resource(identifier); for (const auto &pair : properties) { resource.setProperty(pair.first, pair.second); } - Sink::Store::modify(resource) + Store::modify(resource) .onError([](const KAsync::Error &error) { qWarning() << "Error while modifying resource: " << error.errorMessage; }) @@ -231,7 +234,7 @@ static QByteArray saveResource(const QByteArray &accountIdentifier, const QByteA for (const auto &pair : properties) { resource.setProperty(pair.first, pair.second); } - Sink::Store::create(resource) + Store::create(resource) .onError([](const KAsync::Error &error) { qWarning() << "Error while creating resource: " << error.errorMessage; }) @@ -243,7 +246,7 @@ static QByteArray saveResource(const QByteArray &accountIdentifier, const QByteA void AccountSettings::saveImapResource() { - mImapIdentifier = saveResource(mAccountIdentifier, mImapIdentifier, { + mImapIdentifier = saveResource(mAccountIdentifier, mImapIdentifier, { {"server", mImapServer}, {"username", mImapUsername}, {"password", mImapPassword}, @@ -252,14 +255,14 @@ void AccountSettings::saveImapResource() void AccountSettings::saveMaildirResource() { - mMaildirIdentifier = saveResource(mAccountIdentifier, mMaildirIdentifier, { + mMaildirIdentifier = saveResource(mAccountIdentifier, mMaildirIdentifier, { {"path", mPath}, }); } void AccountSettings::saveMailtransportResource() { - mMailtransportIdentifier = saveResource(mAccountIdentifier, mMailtransportIdentifier, { + mMailtransportIdentifier = saveResource(mAccountIdentifier, mMailtransportIdentifier, { {"server", mSmtpServer}, {"username", mSmtpUsername}, {"password", mSmtpPassword}, @@ -269,21 +272,21 @@ void AccountSettings::saveMailtransportResource() void AccountSettings::saveIdentity() { if (!mIdentityIdentifier.isEmpty()) { - Sink::ApplicationDomain::Identity identity(mMailtransportIdentifier); + Identity identity(mMailtransportIdentifier); identity.setProperty("username", mUsername); identity.setProperty("address", mEmailAddress); - Sink::Store::modify(identity) + Store::modify(identity) .onError([](const KAsync::Error &error) { qWarning() << "Error while modifying identity: " << error.errorMessage; }) .exec(); } else { - auto identity = Sink::ApplicationDomain::ApplicationDomainType::createEntity(); + auto identity = ApplicationDomainType::createEntity(); mIdentityIdentifier = identity.identifier(); identity.setProperty("account", mAccountIdentifier); identity.setProperty("username", mUsername); identity.setProperty("address", mEmailAddress); - Sink::Store::create(identity) + Store::create(identity) .onError([](const KAsync::Error &error) { qWarning() << "Error while creating identity: " << error.errorMessage; }) @@ -296,8 +299,8 @@ void AccountSettings::removeResource(const QByteArray &identifier) if (identifier.isEmpty()) { qWarning() << "We're missing an identifier"; } else { - Sink::ApplicationDomain::SinkResource resource("", identifier, 0, QSharedPointer::create()); - Sink::Store::remove(resource) + SinkResource resource("", identifier, 0, QSharedPointer::create()); + Store::remove(resource) .onError([](const KAsync::Error &error) { qWarning() << "Error while removing resource: " << error.errorMessage; }) @@ -310,8 +313,8 @@ void AccountSettings::removeAccount() if (mAccountIdentifier.isEmpty()) { qWarning() << "We're missing an identifier"; } else { - Sink::ApplicationDomain::SinkAccount account("", mAccountIdentifier, 0, QSharedPointer::create()); - Sink::Store::remove(account) + SinkAccount account("", mAccountIdentifier, 0, QSharedPointer::create()); + Store::remove(account) .onError([](const KAsync::Error &error) { qWarning() << "Error while removing account: " << error.errorMessage; }) @@ -324,8 +327,8 @@ void AccountSettings::removeIdentity() if (mIdentityIdentifier.isEmpty()) { qWarning() << "We're missing an identifier"; } else { - Sink::ApplicationDomain::Identity identity("", mIdentityIdentifier, 0, QSharedPointer::create()); - Sink::Store::remove(identity) + Identity identity("", mIdentityIdentifier, 0, QSharedPointer::create()); + Store::remove(identity) .onError([](const KAsync::Error &error) { qWarning() << "Error while removing identity: " << error.errorMessage; }) -- cgit v1.2.3 From 5fa8608e9877eab40336a60ed8ed979aaf3cfbd0 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 5 Oct 2016 22:42:53 +0200 Subject: Adapted to new API --- framework/domain/accountfactory.cpp | 2 +- framework/domain/actions/sinkactions.cpp | 16 +++++++-------- framework/domain/folderlistmodel.cpp | 4 ++-- framework/domain/maillistmodel.cpp | 2 +- framework/domain/settings/accountsettings.cpp | 28 +++++++++++++-------------- 5 files changed, 26 insertions(+), 26 deletions(-) (limited to 'framework/domain') diff --git a/framework/domain/accountfactory.cpp b/framework/domain/accountfactory.cpp index 6261eaf1..182a0a1d 100644 --- a/framework/domain/accountfactory.cpp +++ b/framework/domain/accountfactory.cpp @@ -43,7 +43,7 @@ QString AccountFactory::name() const void AccountFactory::setAccountId(const QString &accountId) { mAccountId = accountId; - Sink::Store::fetchOne(Sink::Query::IdentityFilter(accountId.toUtf8())) + Sink::Store::fetchOne(Sink::Query().filter(accountId.toUtf8())) .syncThen([this](const Sink::ApplicationDomain::SinkAccount &account) { mAccountType = account.getProperty("type").toByteArray(); loadPackage(); diff --git a/framework/domain/actions/sinkactions.cpp b/framework/domain/actions/sinkactions.cpp index e79e79c9..cc8d324e 100644 --- a/framework/domain/actions/sinkactions.cpp +++ b/framework/domain/actions/sinkactions.cpp @@ -85,7 +85,7 @@ static ActionHandlerHelper synchronizeHandler("org.kde.kube.actions.synchronize" [](Context *context) { if (auto folder = context->property("folder").value()) { SinkLog() << "Synchronizing resource " << folder->resourceInstanceIdentifier(); - Store::synchronize(Query::ResourceFilter(folder->resourceInstanceIdentifier())).exec(); + Store::synchronize(Query().resourceFilter(folder->resourceInstanceIdentifier())).exec(); } else { SinkLog() << "Synchronizing all"; Store::synchronize(Query()).exec(); @@ -106,7 +106,7 @@ static ActionHandlerHelper sendMailHandler("org.kde.kube.actions.sendmail", Query query; query.containsFilter(ApplicationDomain::ResourceCapabilities::Mail::transport); - query.filter(ApplicationDomain::SinkAccount(accountId)); + query.filter(accountId); Store::fetchAll(query) .then>([=](const QList &resources) -> KAsync::Job { if (!resources.isEmpty()) { @@ -129,7 +129,7 @@ static ActionHandlerHelper saveAsDraft("org.kde.kube.actions.save-as-draft", return !accountId.isEmpty() && message; }, ActionHandlerHelper::JobHandler([](Context *context) -> KAsync::Job { - SinkWarning() << "executing save as draft"; + SinkLog() << "Executing the save-as-draft action"; const auto accountId = context->property("accountId").value(); const auto message = context->property("message").value(); auto existingMail = context->property("existingMail").value(); @@ -140,18 +140,18 @@ static ActionHandlerHelper saveAsDraft("org.kde.kube.actions.save-as-draft", if (existingMail.identifier().isEmpty()) { Query query; - query.containsFilter(ApplicationDomain::ResourceCapabilities::Mail::drafts); - query.filter(ApplicationDomain::SinkAccount(accountId)); + query.containsFilter(ApplicationDomain::ResourceCapabilities::Mail::drafts); + query.filter(accountId); return Store::fetchOne(query) .then([=](const SinkResource &resource) -> KAsync::Job { Mail mail(resource.identifier()); - mail.setProperty("draft", true); - mail.setBlobProperty("mimeMessage", message->encodedContent()); + mail.setDraft(true); + mail.setMimeMessage(message->encodedContent()); return Store::create(mail); }); } else { SinkWarning() << "Modifying an existing mail" << existingMail.identifier(); - existingMail.setBlobProperty("mimeMessage", message->encodedContent()); + existingMail.setMimeMessage(message->encodedContent()); return Store::modify(existingMail); } }) diff --git a/framework/domain/folderlistmodel.cpp b/framework/domain/folderlistmodel.cpp index e852288f..7cf5ad5d 100644 --- a/framework/domain/folderlistmodel.cpp +++ b/framework/domain/folderlistmodel.cpp @@ -29,7 +29,7 @@ FolderListModel::FolderListModel(QObject *parent) : QIdentityProxyModel() { Query query; query.liveQuery = true; - query.requestedProperties << "name" << "icon" << "parent"; + query.request().request().request(); query.parentProperty = "parent"; runQuery(query); } @@ -79,7 +79,7 @@ void FolderListModel::setAccountId(const QVariant &accountId) //Get all folders of an account auto query = Query(); - query.filter(SinkAccount(account)); + query.resourceFilter(account); query.liveQuery = true; query.request() .request() 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) } Sink::Query query; query.liveQuery = true; - query.resources << folder->resourceInstanceIdentifier(); + query.resourceFilter(folder->resourceInstanceIdentifier()); query.sort(); query.limit = 100; query.request(); diff --git a/framework/domain/settings/accountsettings.cpp b/framework/domain/settings/accountsettings.cpp index 635aef6e..ea798a73 100644 --- a/framework/domain/settings/accountsettings.cpp +++ b/framework/domain/settings/accountsettings.cpp @@ -134,9 +134,9 @@ void AccountSettings::saveAccount() qDebug() << "Saving account " << mAccountIdentifier << mMailtransportIdentifier; Q_ASSERT(!mAccountIdentifier.isEmpty()); SinkAccount account(mAccountIdentifier); - account.setProperty("type", "imap"); - account.setProperty("name", mName); - account.setProperty("icon", mIcon); + account.setAccountType("imap"); + account.setName(mName); + account.setIcon(mIcon); Q_ASSERT(!account.identifier().isEmpty()); Store::modify(account) .onError([](const KAsync::Error &error) { @@ -148,17 +148,17 @@ void AccountSettings::saveAccount() void AccountSettings::loadAccount() { Q_ASSERT(!mAccountIdentifier.isEmpty()); - Store::fetchOne(Query::IdentityFilter(mAccountIdentifier)) + Store::fetchOne(Query().filter(mAccountIdentifier)) .syncThen([this](const SinkAccount &account) { - mIcon = account.getProperty("icon").toString(); - mName = account.getProperty("name").toString(); + mIcon = account.getIcon(); + mName = account.getName(); emit changed(); }).exec(); } void AccountSettings::loadImapResource() { - Store::fetchOne(Query().filter(SinkAccount(mAccountIdentifier)).containsFilter(ResourceCapabilities::Mail::storage)) + Store::fetchOne(Query().filter(mAccountIdentifier).containsFilter(ResourceCapabilities::Mail::storage)) .syncThen([this](const SinkResource &resource) { mImapIdentifier = resource.identifier(); mImapServer = resource.getProperty("server").toString(); @@ -172,7 +172,7 @@ void AccountSettings::loadImapResource() void AccountSettings::loadMaildirResource() { - Store::fetchOne(Query().filter(SinkAccount(mAccountIdentifier)).containsFilter(ResourceCapabilities::Mail::storage)) + Store::fetchOne(Query().filter(mAccountIdentifier).containsFilter(ResourceCapabilities::Mail::storage)) .syncThen([this](const SinkResource &resource) { mMaildirIdentifier = resource.identifier(); auto path = resource.getProperty("path").toString(); @@ -187,7 +187,7 @@ void AccountSettings::loadMaildirResource() void AccountSettings::loadMailtransportResource() { - Store::fetchOne(Query().filter(SinkAccount(mAccountIdentifier)).containsFilter(ResourceCapabilities::Mail::transport)) + Store::fetchOne(Query().filter(mAccountIdentifier).containsFilter(ResourceCapabilities::Mail::transport)) .syncThen([this](const SinkResource &resource) { mMailtransportIdentifier = resource.identifier(); mSmtpServer = resource.getProperty("server").toString(); @@ -202,7 +202,7 @@ void AccountSettings::loadMailtransportResource() void AccountSettings::loadIdentity() { //FIXME this assumes that we only ever have one identity per account - Store::fetchOne(Query().filter(SinkAccount(mAccountIdentifier))) + Store::fetchOne(Query().filter(mAccountIdentifier)) .syncThen([this](const Identity &identity) { mIdentityIdentifier = identity.identifier(); mUsername = identity.getProperty("username").toString(); @@ -283,7 +283,7 @@ void AccountSettings::saveIdentity() } else { auto identity = ApplicationDomainType::createEntity(); mIdentityIdentifier = identity.identifier(); - identity.setProperty("account", mAccountIdentifier); + identity.setAccount(mAccountIdentifier); identity.setProperty("username", mUsername); identity.setProperty("address", mEmailAddress); Store::create(identity) @@ -299,7 +299,7 @@ void AccountSettings::removeResource(const QByteArray &identifier) if (identifier.isEmpty()) { qWarning() << "We're missing an identifier"; } else { - SinkResource resource("", identifier, 0, QSharedPointer::create()); + SinkResource resource(identifier); Store::remove(resource) .onError([](const KAsync::Error &error) { qWarning() << "Error while removing resource: " << error.errorMessage; @@ -313,7 +313,7 @@ void AccountSettings::removeAccount() if (mAccountIdentifier.isEmpty()) { qWarning() << "We're missing an identifier"; } else { - SinkAccount account("", mAccountIdentifier, 0, QSharedPointer::create()); + SinkAccount account(mAccountIdentifier); Store::remove(account) .onError([](const KAsync::Error &error) { qWarning() << "Error while removing account: " << error.errorMessage; @@ -327,7 +327,7 @@ void AccountSettings::removeIdentity() if (mIdentityIdentifier.isEmpty()) { qWarning() << "We're missing an identifier"; } else { - Identity identity("", mIdentityIdentifier, 0, QSharedPointer::create()); + Identity identity(mIdentityIdentifier); Store::remove(identity) .onError([](const KAsync::Error &error) { qWarning() << "Error while removing identity: " << error.errorMessage; -- cgit v1.2.3