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

0001 /*
0002     SPDX-FileCopyrightText: 2008 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "collectioncopyjob.h"
0008 #include "collection.h"
0009 #include "job_p.h"
0010 #include "private/protocol_p.h"
0011 
0012 #include <KLocalizedString>
0013 
0014 using namespace Akonadi;
0015 
0016 class Akonadi::CollectionCopyJobPrivate : public JobPrivate
0017 {
0018 public:
0019     explicit CollectionCopyJobPrivate(CollectionCopyJob *parent)
0020         : JobPrivate(parent)
0021     {
0022     }
0023 
0024     Collection mSource;
0025     Collection mTarget;
0026 
0027     QString jobDebuggingString() const override;
0028 };
0029 
0030 QString Akonadi::CollectionCopyJobPrivate::jobDebuggingString() const
0031 {
0032     return QStringLiteral("copy collection from %1 to %2").arg(mSource.id()).arg(mTarget.id());
0033 }
0034 
0035 CollectionCopyJob::CollectionCopyJob(const Collection &source, const Collection &target, QObject *parent)
0036     : Job(new CollectionCopyJobPrivate(this), parent)
0037 {
0038     Q_D(CollectionCopyJob);
0039 
0040     d->mSource = source;
0041     d->mTarget = target;
0042 }
0043 
0044 CollectionCopyJob::~CollectionCopyJob()
0045 {
0046 }
0047 
0048 void CollectionCopyJob::doStart()
0049 {
0050     Q_D(CollectionCopyJob);
0051 
0052     if (!d->mSource.isValid() && d->mSource.remoteId().isEmpty()) {
0053         setError(Unknown);
0054         setErrorText(i18n("Invalid collection to copy"));
0055         emitResult();
0056         return;
0057     }
0058     if (!d->mTarget.isValid() && d->mTarget.remoteId().isEmpty()) {
0059         setError(Unknown);
0060         setErrorText(i18n("Invalid destination collection"));
0061         emitResult();
0062         return;
0063     }
0064     d->sendCommand(Protocol::CopyCollectionCommandPtr::create(d->mSource.id(), d->mTarget.id()));
0065 }
0066 
0067 bool CollectionCopyJob::doHandleResponse(qint64 tag, const Protocol::CommandPtr &response)
0068 {
0069     if (!response->isResponse() || response->type() != Protocol::Command::CopyCollection) {
0070         return Job::doHandleResponse(tag, response);
0071     }
0072 
0073     return true;
0074 }
0075 
0076 #include "moc_collectioncopyjob.cpp"