File indexing completed on 2024-11-10 04:40:29

0001 /*
0002     SPDX-FileCopyrightText: 2009 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "collectionmovejob.h"
0008 #include "changemediator_p.h"
0009 #include "collection.h"
0010 #include "job_p.h"
0011 #include "private/protocol_p.h"
0012 #include "protocolhelper_p.h"
0013 
0014 #include <KLocalizedString>
0015 
0016 using namespace Akonadi;
0017 
0018 class Akonadi::CollectionMoveJobPrivate : public JobPrivate
0019 {
0020 public:
0021     explicit CollectionMoveJobPrivate(CollectionMoveJob *parent)
0022         : JobPrivate(parent)
0023     {
0024     }
0025 
0026     QString jobDebuggingString() const override;
0027     Collection destination;
0028     Collection collection;
0029 
0030     Q_DECLARE_PUBLIC(CollectionMoveJob)
0031 };
0032 
0033 QString Akonadi::CollectionMoveJobPrivate::jobDebuggingString() const
0034 {
0035     return QStringLiteral("Move collection from %1 to %2").arg(collection.id()).arg(destination.id());
0036 }
0037 
0038 CollectionMoveJob::CollectionMoveJob(const Collection &collection, const Collection &destination, QObject *parent)
0039     : Job(new CollectionMoveJobPrivate(this), parent)
0040 {
0041     Q_D(CollectionMoveJob);
0042     d->destination = destination;
0043     d->collection = collection;
0044 }
0045 
0046 void CollectionMoveJob::doStart()
0047 {
0048     Q_D(CollectionMoveJob);
0049 
0050     if (!d->collection.isValid()) {
0051         setError(Job::Unknown);
0052         setErrorText(i18n("No objects specified for moving"));
0053         emitResult();
0054         return;
0055     }
0056 
0057     if (!d->destination.isValid() && d->destination.remoteId().isEmpty()) {
0058         setError(Job::Unknown);
0059         setErrorText(i18n("No valid destination specified"));
0060         emitResult();
0061         return;
0062     }
0063 
0064     const Scope colScope = ProtocolHelper::entitySetToScope(Collection::List() << d->collection);
0065     const Scope destScope = ProtocolHelper::entitySetToScope(Collection::List() << d->destination);
0066 
0067     d->sendCommand(Protocol::MoveCollectionCommandPtr::create(colScope, destScope));
0068 
0069     ChangeMediator::invalidateCollection(d->collection);
0070 }
0071 
0072 bool CollectionMoveJob::doHandleResponse(qint64 tag, const Protocol::CommandPtr &response)
0073 {
0074     if (!response->isResponse() || response->type() != Protocol::Command::MoveCollection) {
0075         return Job::doHandleResponse(tag, response);
0076     }
0077 
0078     return true;
0079 }
0080 
0081 #include "moc_collectionmovejob.cpp"