markascommandhelper.cpp 1.34 KB
Newer Older
Laurent Montel's avatar
Laurent Montel committed
1
2
3
4
5
6
/*
    SPDX-FileCopyrightText: 2022 Laurent Montel <montel@kde.org>

    SPDX-License-Identifier: LGPL-2.0-or-later
*/

Laurent Montel's avatar
Laurent Montel committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "markascommandhelper_p.h"

#include "akonadi_mime_debug.h"
#include <Akonadi/ItemModifyJob>

using namespace Akonadi;
MarkAsCommandHelper::MarkAsCommandHelper(QObject *parent)
    : QObject{parent}
{
}

MarkAsCommandHelper::~MarkAsCommandHelper() = default;

void MarkAsCommandHelper::start()
{
    if (!mItemsToModify.isEmpty()) {
        auto modifyJob = new Akonadi::ItemModifyJob(mItemsToModify, this);
        modifyJob->setIgnorePayload(true);
        modifyJob->disableRevisionCheck();
        connect(modifyJob, &Akonadi::ItemModifyJob::result, this, &MarkAsCommandHelper::slotModifyItemDone);
    } else {
        emitResult(Akonadi::CommandBase::OK);
        deleteLater();
    }
}

const Akonadi::Item::List &MarkAsCommandHelper::itemsToModify() const
{
    return mItemsToModify;
}

void MarkAsCommandHelper::setItemsToModify(const Akonadi::Item::List &newItemsToModify)
{
    mItemsToModify = newItemsToModify;
}

void MarkAsCommandHelper::slotModifyItemDone(KJob *job)
{
    if (job && job->error()) {
        qCDebug(AKONADIMIME_LOG) << " Error trying to set item status:" << job->errorText();
        emitResult(Akonadi::CommandBase::Failed);
    } else {
        emitResult(Akonadi::CommandBase::OK);
    }
    deleteLater();
}