/* * Copyright (C) 2014 Christian Mollekopf * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "resourcefacade.h" #include "resourceconfig.h" ResourceFacade::ResourceFacade(const QByteArray &) : Akonadi2::StoreFacade() { } ResourceFacade::~ResourceFacade() { } KAsync::Job ResourceFacade::create(const Akonadi2::ApplicationDomain::AkonadiResource &resource) { return KAsync::start([resource, this]() { const QByteArray identifier = resource.getProperty("identifier").toByteArray(); const QByteArray type = resource.getProperty("type").toByteArray(); ResourceConfig::addResource(identifier, type); }); } KAsync::Job ResourceFacade::modify(const Akonadi2::ApplicationDomain::AkonadiResource &resource) { return KAsync::null(); } KAsync::Job ResourceFacade::remove(const Akonadi2::ApplicationDomain::AkonadiResource &resource) { return KAsync::start([resource, this]() { const QByteArray identifier = resource.getProperty("identifier").toByteArray(); ResourceConfig::removeResource(identifier); }); } KAsync::Job ResourceFacade::load(const Akonadi2::Query &query, const QSharedPointer > &resultProvider) { return KAsync::start([query, resultProvider]() { const auto configuredResources = ResourceConfig::getResources(); for (const auto &res : configuredResources.keys()) { const auto type = configuredResources.value(res); if (!query.propertyFilter.contains("type") || query.propertyFilter.value("type").toByteArray() == type) { auto resource = Akonadi2::ApplicationDomain::AkonadiResource::Ptr::create(); resource->setProperty("identifier", res); resource->setProperty("type", type); resultProvider->add(resource); } } //TODO initialResultSetComplete should be implicit resultProvider->initialResultSetComplete(); resultProvider->complete(); }); }