File indexing completed on 2024-11-10 04:40:29
0001 /* 0002 SPDX-FileCopyrightText: 2006 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "collectionmodifyjob.h" 0008 0009 #include "changemediator_p.h" 0010 #include "collection_p.h" 0011 #include "collectionstatistics.h" 0012 #include "job_p.h" 0013 #include "persistentsearchattribute.h" 0014 #include "private/protocol_p.h" 0015 #include "protocolhelper_p.h" 0016 0017 using namespace Akonadi; 0018 0019 class Akonadi::CollectionModifyJobPrivate : public JobPrivate 0020 { 0021 public: 0022 explicit CollectionModifyJobPrivate(CollectionModifyJob *parent) 0023 : JobPrivate(parent) 0024 { 0025 } 0026 0027 QString jobDebuggingString() const override 0028 { 0029 return QStringLiteral("Collection Id %1").arg(mCollection.id()); 0030 } 0031 0032 Collection mCollection; 0033 }; 0034 0035 CollectionModifyJob::CollectionModifyJob(const Collection &collection, QObject *parent) 0036 : Job(new CollectionModifyJobPrivate(this), parent) 0037 { 0038 Q_D(CollectionModifyJob); 0039 d->mCollection = collection; 0040 } 0041 0042 CollectionModifyJob::~CollectionModifyJob() 0043 { 0044 } 0045 0046 void CollectionModifyJob::doStart() 0047 { 0048 Q_D(CollectionModifyJob); 0049 0050 Protocol::ModifyCollectionCommandPtr cmd; 0051 try { 0052 cmd = Protocol::ModifyCollectionCommandPtr::create(ProtocolHelper::entityToScope(d->mCollection)); 0053 } catch (const std::exception &e) { 0054 setError(Job::Unknown); 0055 setErrorText(QString::fromUtf8(e.what())); 0056 emitResult(); 0057 return; 0058 } 0059 0060 if (d->mCollection.d_ptr->contentTypesChanged) { 0061 cmd->setMimeTypes(d->mCollection.contentMimeTypes()); 0062 } 0063 if (d->mCollection.parentCollection().id() >= 0) { 0064 cmd->setParentId(d->mCollection.parentCollection().id()); 0065 } 0066 const QString &collectionName = d->mCollection.name(); 0067 if (!collectionName.isEmpty()) { 0068 cmd->setName(collectionName); 0069 } 0070 if (!d->mCollection.remoteId().isNull()) { 0071 cmd->setRemoteId(d->mCollection.remoteId()); 0072 } 0073 if (!d->mCollection.remoteRevision().isNull()) { 0074 cmd->setRemoteRevision(d->mCollection.remoteRevision()); 0075 } 0076 if (d->mCollection.d_ptr->cachePolicyChanged) { 0077 cmd->setCachePolicy(ProtocolHelper::cachePolicyToProtocol(d->mCollection.cachePolicy())); 0078 } 0079 if (d->mCollection.d_ptr->enabledChanged) { 0080 cmd->setEnabled(d->mCollection.enabled()); 0081 } 0082 if (d->mCollection.d_ptr->listPreferenceChanged) { 0083 cmd->setDisplayPref(ProtocolHelper::listPreference(d->mCollection.localListPreference(Collection::ListDisplay))); 0084 cmd->setSyncPref(ProtocolHelper::listPreference(d->mCollection.localListPreference(Collection::ListSync))); 0085 cmd->setIndexPref(ProtocolHelper::listPreference(d->mCollection.localListPreference(Collection::ListIndex))); 0086 } 0087 if (d->mCollection.d_ptr->mAttributeStorage.hasModifiedAttributes()) { 0088 cmd->setAttributes(ProtocolHelper::attributesToProtocol(d->mCollection.d_ptr->mAttributeStorage.modifiedAttributes())); 0089 } 0090 if (auto attr = d->mCollection.attribute<Akonadi::PersistentSearchAttribute>()) { 0091 cmd->setPersistentSearchCollections(attr->queryCollections()); 0092 cmd->setPersistentSearchQuery(attr->queryString()); 0093 cmd->setPersistentSearchRecursive(attr->isRecursive()); 0094 cmd->setPersistentSearchRemote(attr->isRemoteSearchEnabled()); 0095 } 0096 if (!d->mCollection.d_ptr->mAttributeStorage.deletedAttributes().empty()) { 0097 cmd->setRemovedAttributes(d->mCollection.d_ptr->mAttributeStorage.deletedAttributes()); 0098 } 0099 0100 if (cmd->modifiedParts() == Protocol::ModifyCollectionCommand::None) { 0101 emitResult(); 0102 return; 0103 } 0104 0105 d->sendCommand(cmd); 0106 0107 ChangeMediator::invalidateCollection(d->mCollection); 0108 } 0109 0110 bool CollectionModifyJob::doHandleResponse(qint64 tag, const Akonadi::Protocol::CommandPtr &response) 0111 { 0112 Q_D(CollectionModifyJob); 0113 0114 if (!response->isResponse() || response->type() != Protocol::Command::ModifyCollection) { 0115 return Job::doHandleResponse(tag, response); 0116 } 0117 0118 d->mCollection.d_ptr->resetChangeLog(); 0119 return true; 0120 } 0121 0122 Collection CollectionModifyJob::collection() const 0123 { 0124 const Q_D(CollectionModifyJob); 0125 return d->mCollection; 0126 } 0127 0128 #include "moc_collectionmodifyjob.cpp"