File indexing completed on 2024-11-10 04:40:31
0001 /* 0002 SPDX-FileCopyrightText: 2008, 2009 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "collection.h" 0010 #include "item.h" 0011 #include "job.h" 0012 #include "job_p.h" 0013 #include "private/protocol_p.h" 0014 #include "protocolhelper_p.h" 0015 0016 #include <KLocalizedString> 0017 0018 namespace Akonadi 0019 { 0020 /** Shared implementation details between item and collection move jobs. */ 0021 template<typename LinkJob> 0022 class LinkJobImpl : public JobPrivate 0023 { 0024 public: 0025 LinkJobImpl(Job *parent) 0026 : JobPrivate(parent) 0027 { 0028 } 0029 0030 inline void sendCommand(Protocol::LinkItemsCommand::Action action) 0031 { 0032 auto q = static_cast<LinkJob *>(q_func()); // Job would be enough already, but then we don't have access to the non-public stuff... 0033 if (objectsToLink.isEmpty()) { 0034 q->emitResult(); 0035 return; 0036 } 0037 if (!destination.isValid() && destination.remoteId().isEmpty()) { 0038 q->setError(Job::Unknown); 0039 q->setErrorText(i18n("No valid destination specified")); 0040 q->emitResult(); 0041 return; 0042 } 0043 0044 try { 0045 JobPrivate::sendCommand( 0046 Protocol::LinkItemsCommandPtr::create(action, ProtocolHelper::entitySetToScope(objectsToLink), ProtocolHelper::entityToScope(destination))); 0047 } catch (const std::exception &e) { 0048 q->setError(Job::Unknown); 0049 q->setErrorText(QString::fromUtf8(e.what())); 0050 q->emitResult(); 0051 return; 0052 } 0053 } 0054 0055 inline bool handleResponse(qint64 tag, const Protocol::CommandPtr &response) 0056 { 0057 auto q = static_cast<LinkJob *>(q_func()); 0058 if (!response->isResponse() || response->type() != Protocol::Command::LinkItems) { 0059 return q->Job::doHandleResponse(tag, response); 0060 } 0061 0062 return true; 0063 } 0064 0065 Item::List objectsToLink; 0066 Collection destination; 0067 }; 0068 0069 }