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') 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