File indexing completed on 2024-11-24 04:44:35

0001 /*  This file is part of the KDE project
0002     SPDX-FileCopyrightText: 2009 Kevin Krammer <kevin.krammer@gmx.at>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "session_p.h"
0008 
0009 #include "collectioncreatejob.h"
0010 #include "collectiondeletejob.h"
0011 #include "collectionfetchjob.h"
0012 #include "collectionmodifyjob.h"
0013 #include "collectionmovejob.h"
0014 #include "itemcreatejob.h"
0015 #include "itemfetchjob.h"
0016 #include "itemmodifyjob.h"
0017 #include "itemmovejob.h"
0018 #include "storecompactjob.h"
0019 
0020 using namespace Akonadi;
0021 
0022 FileStore::AbstractJobSession::AbstractJobSession(QObject *parent)
0023     : QObject(parent)
0024 {
0025 }
0026 
0027 FileStore::AbstractJobSession::~AbstractJobSession() = default;
0028 
0029 void FileStore::AbstractJobSession::notifyCollectionsReceived(FileStore::Job *job, const Collection::List &collections)
0030 {
0031     auto fetchJob = qobject_cast<FileStore::CollectionFetchJob *>(job);
0032     if (fetchJob != nullptr) {
0033         fetchJob->handleCollectionsReceived(collections);
0034     }
0035 }
0036 
0037 void FileStore::AbstractJobSession::notifyCollectionCreated(FileStore::Job *job, const Collection &collection)
0038 {
0039     auto createJob = qobject_cast<FileStore::CollectionCreateJob *>(job);
0040     if (createJob != nullptr) {
0041         createJob->handleCollectionCreated(collection);
0042     }
0043 }
0044 
0045 void FileStore::AbstractJobSession::notifyCollectionDeleted(FileStore::Job *job, const Collection &collection)
0046 {
0047     auto deleteJob = qobject_cast<FileStore::CollectionDeleteJob *>(job);
0048     if (deleteJob != nullptr) {
0049         deleteJob->handleCollectionDeleted(collection);
0050     }
0051 }
0052 
0053 void FileStore::AbstractJobSession::notifyCollectionModified(FileStore::Job *job, const Collection &collection)
0054 {
0055     auto modifyJob = qobject_cast<FileStore::CollectionModifyJob *>(job);
0056     if (modifyJob != nullptr) {
0057         modifyJob->handleCollectionModified(collection);
0058     }
0059 }
0060 
0061 void FileStore::AbstractJobSession::notifyCollectionMoved(FileStore::Job *job, const Collection &collection)
0062 {
0063     auto moveJob = qobject_cast<FileStore::CollectionMoveJob *>(job);
0064     if (moveJob != nullptr) {
0065         moveJob->handleCollectionMoved(collection);
0066     }
0067 }
0068 
0069 void FileStore::AbstractJobSession::notifyItemsReceived(FileStore::Job *job, const Item::List &items)
0070 {
0071     auto fetchJob = qobject_cast<FileStore::ItemFetchJob *>(job);
0072     if (fetchJob != nullptr) {
0073         fetchJob->handleItemsReceived(items);
0074     }
0075 }
0076 
0077 void FileStore::AbstractJobSession::notifyItemCreated(FileStore::Job *job, const Item &item)
0078 {
0079     auto createJob = qobject_cast<FileStore::ItemCreateJob *>(job);
0080     if (createJob != nullptr) {
0081         createJob->handleItemCreated(item);
0082     }
0083 }
0084 
0085 void FileStore::AbstractJobSession::notifyItemModified(FileStore::Job *job, const Item &item)
0086 {
0087     auto modifyJob = qobject_cast<FileStore::ItemModifyJob *>(job);
0088     if (modifyJob != nullptr) {
0089         modifyJob->handleItemModified(item);
0090     }
0091 }
0092 
0093 void FileStore::AbstractJobSession::notifyItemMoved(FileStore::Job *job, const Item &item)
0094 {
0095     auto moveJob = qobject_cast<FileStore::ItemMoveJob *>(job);
0096     if (moveJob != nullptr) {
0097         moveJob->handleItemMoved(item);
0098     }
0099 }
0100 
0101 void FileStore::AbstractJobSession::notifyCollectionsChanged(FileStore::Job *job, const Collection::List &collections)
0102 {
0103     auto compactJob = qobject_cast<FileStore::StoreCompactJob *>(job);
0104     if (compactJob != nullptr) {
0105         compactJob->handleCollectionsChanged(collections);
0106     }
0107 }
0108 
0109 void FileStore::AbstractJobSession::notifyItemsChanged(FileStore::Job *job, const Item::List &items)
0110 {
0111     auto compactJob = qobject_cast<FileStore::StoreCompactJob *>(job);
0112     if (compactJob != nullptr) {
0113         compactJob->handleItemsChanged(items);
0114     }
0115 }
0116 
0117 void FileStore::AbstractJobSession::setError(FileStore::Job *job, int errorCode, const QString &errorText)
0118 {
0119     job->setError(errorCode);
0120     job->setErrorText(errorText);
0121 }
0122 
0123 void FileStore::AbstractJobSession::emitResult(FileStore::Job *job)
0124 {
0125     removeJob(job);
0126 
0127     job->emitResult();
0128 }
0129 
0130 #include "moc_session_p.cpp"