File indexing completed on 2024-05-12 05:26:06

0001 /*
0002  * Copyright (C) 2015 Christian Mollekopf <chrigi_1@fastmail.fm>
0003  *
0004  * This library is free software; you can redistribute it and/or
0005  * modify it under the terms of the GNU Lesser General Public
0006  * License as published by the Free Software Foundation; either
0007  * version 2.1 of the License, or (at your option) version 3, or any
0008  * later version accepted by the membership of KDE e.V. (or its
0009  * successor approved by the membership of KDE e.V.), which shall
0010  * act as a proxy defined in Section 6 of version 3 of the license.
0011  *
0012  * This library is distributed in the hope that it will be useful,
0013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015  * Lesser General Public License for more details.
0016  *
0017  * You should have received a copy of the GNU Lesser General Public
0018  * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
0019  */
0020 
0021 #pragma once
0022 
0023 #include "sink_export.h"
0024 #include <QString>
0025 #include <QSharedPointer>
0026 
0027 #include <KAsync/Async>
0028 
0029 #include "query.h"
0030 #include "applicationdomaintype.h"
0031 
0032 class QAbstractItemModel;
0033 
0034 namespace Sink {
0035 
0036 /**
0037  * The unified Sink Store.
0038  *
0039  * This is the primary interface for clients to interact with Sink.
0040  * It provides a unified store where all data provided by various resources can be accessed and modified.
0041  */
0042 namespace Store {
0043 
0044 QString SINK_EXPORT storageLocation();
0045 
0046 // Must be the same as in ModelResult
0047 enum Roles
0048 {
0049     DomainObjectRole = Qt::UserRole + 1,
0050     ChildrenFetchedRole,
0051     DomainObjectBaseRole,
0052     StatusRole, //ApplicationDomain::SyncStatus
0053     WarningRole, //ApplicationDomain::Warning, only if status == warning || status == error
0054     ProgressRole //ApplicationDomain::Progress
0055 };
0056 
0057 /**
0058 * Asynchronusly load a dataset with tree structure information
0059 */
0060 template <class DomainType>
0061 QSharedPointer<QAbstractItemModel> SINK_EXPORT loadModel(const Query &query);
0062 
0063 template <class DomainType>
0064 void SINK_EXPORT updateModel(const Query &query, const QSharedPointer<QAbstractItemModel> &model);
0065 
0066 /**
0067  * Create a new entity.
0068  */
0069 template <class DomainType>
0070 KAsync::Job<void> SINK_EXPORT create(const DomainType &domainObject);
0071 
0072 /**
0073  * Modify an entity.
0074  *
0075  * This includes moving etc. since these are also simple settings on a property.
0076  * Note that the modification will be dropped if there is no changedProperty on the domain object.
0077  */
0078 template <class DomainType>
0079 KAsync::Job<void> SINK_EXPORT modify(const DomainType &domainObject);
0080 
0081 /**
0082  * Modify a set of entities identified by @param query.
0083  * 
0084  * Note that the modification will be dropped if there is no changedProperty on the domain object.
0085  */
0086 template <class DomainType>
0087 KAsync::Job<void> SINK_EXPORT modify(const Query &query, const DomainType &domainObject);
0088 
0089 /**
0090  * Remove an entity.
0091  */
0092 template <class DomainType>
0093 KAsync::Job<void> SINK_EXPORT remove(const DomainType &domainObject);
0094 
0095 /**
0096  * Remove a set of entities identified by @param query.
0097  */
0098 template <class DomainType>
0099 KAsync::Job<void> SINK_EXPORT remove(const Query &query);
0100 
0101 /**
0102  * Move an entity to a new resource.
0103  */
0104 template <class DomainType>
0105 KAsync::Job<void> SINK_EXPORT move(const DomainType &domainObject, const QByteArray &newResource);
0106 
0107 /**
0108  * Copy an entity to a new resource.
0109  */
0110 template <class DomainType>
0111 KAsync::Job<void> SINK_EXPORT copy(const DomainType &domainObject, const QByteArray &newResource);
0112 
0113 /**
0114  * Synchronize data to local cache.
0115  */
0116 KAsync::Job<void> SINK_EXPORT synchronize(const Sink::Query &query);
0117 KAsync::Job<void> SINK_EXPORT synchronize(const Sink::SyncScope &query);
0118 
0119 /**
0120  * Abort all running synchronization commands.
0121  */
0122 KAsync::Job<void> SINK_EXPORT abortSynchronization(const Sink::SyncScope &scope);
0123 
0124 /**
0125  * Removes all resource data from disk.
0126  *
0127  * This will not touch the configuration. All commands that that arrived at the resource before this command will be dropped. All commands that arrived later will be executed.
0128  */
0129 KAsync::Job<void> SINK_EXPORT removeDataFromDisk(const QByteArray &resourceIdentifier);
0130 
0131 struct UpgradeResult {
0132     bool upgradeExecuted;
0133 };
0134 
0135 /**
0136  * Run upgrade jobs.
0137  *
0138  * Run this to upgrade your local database to a new version.
0139  * Note that this may:
0140  * * take a while
0141  * * remove some/all of your local caches
0142  *
0143  * Note: The initial implementation simply calls removeDataFromDisk for all resources.
0144  */
0145 KAsync::Job<UpgradeResult> SINK_EXPORT upgrade();
0146 
0147 template <class DomainType>
0148 KAsync::Job<DomainType> SINK_EXPORT fetchOne(const Sink::Query &query);
0149 
0150 template <class DomainType>
0151 KAsync::Job<QList<typename DomainType::Ptr>> SINK_EXPORT fetchAll(const Sink::Query &query);
0152 
0153 template <class DomainType>
0154 KAsync::Job<QList<typename DomainType::Ptr>> SINK_EXPORT fetch(const Sink::Query &query, int minimumAmount = 0);
0155 
0156 template <class DomainType>
0157 DomainType SINK_EXPORT readOne(const Sink::Query &query);
0158 
0159 template <class DomainType>
0160 QList<DomainType> SINK_EXPORT read(const Sink::Query &query);
0161 }
0162 }