Akonadi Mime

markascommandhelper.cpp
1/*
2 SPDX-FileCopyrightText: 2022-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "markascommandhelper_p.h"
8
9#include "akonadi_mime_debug.h"
10#include <Akonadi/ItemModifyJob>
11
12using namespace Akonadi;
13namespace
14{
15static int sNumberMaxElement = 500;
16}
17MarkAsCommandHelper::MarkAsCommandHelper(QObject *parent)
18 : QObject{parent}
19{
20}
21
22MarkAsCommandHelper::~MarkAsCommandHelper() = default;
23
24void MarkAsCommandHelper::start()
25{
26 if (mItemsToModify.isEmpty()) {
27 emitResult(Akonadi::CommandBase::OK);
28 deleteLater();
29 } else {
30 mIndex = 0;
31 modifyMessages();
32 }
33}
34
35void MarkAsCommandHelper::modifyMessages()
36{
37 auto listElement = mItemsToModify.mid(mIndex, qMin(mIndex + sNumberMaxElement, mItemsToModify.count()));
38 // qDebug() << " mIndex " << mIndex << "listElement . count " << listElement.count();
39 mIndex += sNumberMaxElement;
40 auto modifyJob = new Akonadi::ItemModifyJob(listElement, this);
41 modifyJob->setIgnorePayload(true);
42 modifyJob->disableRevisionCheck();
43 connect(modifyJob, &Akonadi::ItemModifyJob::result, this, &MarkAsCommandHelper::slotModifyItemDone);
44}
45
46const Akonadi::Item::List &MarkAsCommandHelper::itemsToModify() const
47{
48 return mItemsToModify;
49}
50
51void MarkAsCommandHelper::setItemsToModify(const Akonadi::Item::List &newItemsToModify)
52{
53 mItemsToModify = newItemsToModify;
54}
55
56void MarkAsCommandHelper::slotModifyItemDone(KJob *job)
57{
58 if (job && job->error()) {
59 qCDebug(AKONADIMIME_LOG) << " Error trying to set item status:" << job->errorText();
60 emitResult(Akonadi::CommandBase::Failed);
61 }
62 if (mIndex > mItemsToModify.count()) {
63 qCDebug(AKONADIMIME_LOG) << " finish";
64 emitResult(Akonadi::CommandBase::OK);
65 deleteLater();
66 } else {
67 // Modify more messages
68 modifyMessages();
69 }
70}
71
72#include "moc_markascommandhelper_p.cpp"
int error() const
void result(KJob *job)
QString errorText() const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:04:17 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.