File indexing completed on 2024-05-12 05:11:10
0001 /* 0002 SPDX-FileCopyrightText: 2022-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "markascommandhelper_p.h" 0008 0009 #include "akonadi_mime_debug.h" 0010 #include <Akonadi/ItemModifyJob> 0011 0012 using namespace Akonadi; 0013 namespace 0014 { 0015 static int sNumberMaxElement = 500; 0016 } 0017 MarkAsCommandHelper::MarkAsCommandHelper(QObject *parent) 0018 : QObject{parent} 0019 { 0020 } 0021 0022 MarkAsCommandHelper::~MarkAsCommandHelper() = default; 0023 0024 void MarkAsCommandHelper::start() 0025 { 0026 if (mItemsToModify.isEmpty()) { 0027 emitResult(Akonadi::CommandBase::OK); 0028 deleteLater(); 0029 } else { 0030 mIndex = 0; 0031 modifyMessages(); 0032 } 0033 } 0034 0035 void MarkAsCommandHelper::modifyMessages() 0036 { 0037 auto listElement = mItemsToModify.mid(mIndex, qMin(mIndex + sNumberMaxElement, mItemsToModify.count())); 0038 // qDebug() << " mIndex " << mIndex << "listElement . count " << listElement.count(); 0039 mIndex += sNumberMaxElement; 0040 auto modifyJob = new Akonadi::ItemModifyJob(listElement, this); 0041 modifyJob->setIgnorePayload(true); 0042 modifyJob->disableRevisionCheck(); 0043 connect(modifyJob, &Akonadi::ItemModifyJob::result, this, &MarkAsCommandHelper::slotModifyItemDone); 0044 } 0045 0046 const Akonadi::Item::List &MarkAsCommandHelper::itemsToModify() const 0047 { 0048 return mItemsToModify; 0049 } 0050 0051 void MarkAsCommandHelper::setItemsToModify(const Akonadi::Item::List &newItemsToModify) 0052 { 0053 mItemsToModify = newItemsToModify; 0054 } 0055 0056 void MarkAsCommandHelper::slotModifyItemDone(KJob *job) 0057 { 0058 if (job && job->error()) { 0059 qCDebug(AKONADIMIME_LOG) << " Error trying to set item status:" << job->errorText(); 0060 emitResult(Akonadi::CommandBase::Failed); 0061 } 0062 if (mIndex > mItemsToModify.count()) { 0063 qCDebug(AKONADIMIME_LOG) << " finish"; 0064 emitResult(Akonadi::CommandBase::OK); 0065 deleteLater(); 0066 } else { 0067 // Modify more messages 0068 modifyMessages(); 0069 } 0070 } 0071 0072 #include "moc_markascommandhelper_p.cpp"