File indexing completed on 2024-11-10 04:40:29
0001 /* 0002 SPDX-FileCopyrightText: 2008 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "itemcopyjob.h" 0008 0009 #include "collection.h" 0010 #include "job_p.h" 0011 #include "private/protocol_p.h" 0012 #include "protocolhelper_p.h" 0013 0014 using namespace Akonadi; 0015 0016 class Akonadi::ItemCopyJobPrivate : public JobPrivate 0017 { 0018 public: 0019 explicit ItemCopyJobPrivate(ItemCopyJob *parent) 0020 : JobPrivate(parent) 0021 { 0022 } 0023 QString jobDebuggingString() const override; 0024 0025 Item::List mItems; 0026 Collection mTarget; 0027 }; 0028 0029 QString Akonadi::ItemCopyJobPrivate::jobDebuggingString() const 0030 { 0031 QString str = QStringLiteral("Copy items : "); 0032 const int nbItems = mItems.count(); 0033 for (int i = 0; i < nbItems; ++i) { 0034 if (i != 0) { 0035 str += QLatin1Char(','); 0036 } 0037 str += QString::number(mItems.at(i).id()); 0038 } 0039 return str + QStringLiteral(" to collection %1").arg(mTarget.id()); 0040 } 0041 0042 ItemCopyJob::ItemCopyJob(const Item &item, const Collection &target, QObject *parent) 0043 : Job(new ItemCopyJobPrivate(this), parent) 0044 { 0045 Q_D(ItemCopyJob); 0046 0047 d->mItems << item; 0048 d->mTarget = target; 0049 } 0050 0051 ItemCopyJob::ItemCopyJob(const Item::List &items, const Collection &target, QObject *parent) 0052 : Job(new ItemCopyJobPrivate(this), parent) 0053 { 0054 Q_D(ItemCopyJob); 0055 0056 d->mItems = items; 0057 d->mTarget = target; 0058 } 0059 0060 ItemCopyJob::~ItemCopyJob() 0061 { 0062 } 0063 0064 void ItemCopyJob::doStart() 0065 { 0066 Q_D(ItemCopyJob); 0067 0068 try { 0069 d->sendCommand(Protocol::CopyItemsCommandPtr::create(ProtocolHelper::entitySetToScope(d->mItems), ProtocolHelper::entityToScope(d->mTarget))); 0070 } catch (std::exception &e) { 0071 setError(Unknown); 0072 setErrorText(QString::fromUtf8(e.what())); 0073 emitResult(); 0074 } 0075 } 0076 0077 bool ItemCopyJob::doHandleResponse(qint64 tag, const Protocol::CommandPtr &response) 0078 { 0079 if (!response->isResponse() || response->type() != Protocol::Command::CopyItems) { 0080 return Job::doHandleResponse(tag, response); 0081 } 0082 0083 return true; 0084 } 0085 0086 #include "moc_itemcopyjob.cpp"