Messagelib

modifymessagedisplayformatjob.cpp
1/*
2 SPDX-FileCopyrightText: 2014-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "modifymessagedisplayformatjob.h"
8#include "messageviewer_debug.h"
9
10#include <Akonadi/ItemModifyJob>
11#include <Akonadi/Session>
12
13#include "viewer/messagedisplayformatattribute.h"
14
15using namespace MessageViewer;
16ModifyMessageDisplayFormatJob::ModifyMessageDisplayFormatJob(Akonadi::Session *session, QObject *parent)
17 : QObject(parent)
18 , mSession(session)
19{
20}
21
22ModifyMessageDisplayFormatJob::~ModifyMessageDisplayFormatJob() = default;
23
24void ModifyMessageDisplayFormatJob::setRemoteContent(bool remote)
25{
26 mRemoteContent = remote;
27}
28
29void ModifyMessageDisplayFormatJob::setMessageFormat(Viewer::DisplayFormatMessage format)
30{
31 mMessageFormat = format;
32}
33
34void ModifyMessageDisplayFormatJob::setResetFormat(bool resetFormat)
35{
36 mResetFormat = resetFormat;
37}
38
39void ModifyMessageDisplayFormatJob::start()
40{
41 if (mMessageItem.isValid()) {
42 if (mResetFormat) {
43 resetDisplayFormat();
44 } else {
45 modifyDisplayFormat();
46 }
47 } else {
48 qCDebug(MESSAGEVIEWER_LOG) << " messageItem doesn't exist";
50 }
51}
52
53void ModifyMessageDisplayFormatJob::setMessageItem(const Akonadi::Item &messageItem)
54{
55 mMessageItem = messageItem;
56}
57
58void ModifyMessageDisplayFormatJob::resetDisplayFormat()
59{
61 auto modify = new Akonadi::ItemModifyJob(mMessageItem, mSession);
62 modify->setIgnorePayload(true);
63 modify->disableRevisionCheck();
64 connect(modify, &KJob::result, this, &ModifyMessageDisplayFormatJob::slotModifyItemDone);
65}
66
67void ModifyMessageDisplayFormatJob::modifyDisplayFormat()
68{
70 attr->setRemoteContent(mRemoteContent);
71 attr->setMessageFormat(mMessageFormat);
72 auto modify = new Akonadi::ItemModifyJob(mMessageItem, mSession);
73 modify->setIgnorePayload(true);
74 modify->disableRevisionCheck();
75 connect(modify, &KJob::result, this, &ModifyMessageDisplayFormatJob::slotModifyItemDone);
76}
77
78void ModifyMessageDisplayFormatJob::slotModifyItemDone(KJob *job)
79{
80 if (job && job->error()) {
81 qCWarning(MESSAGEVIEWER_LOG) << " Error trying to change attribute:" << job->errorText();
82 }
84}
85
86#include "moc_modifymessagedisplayformatjob.cpp"
bool isValid() const
const T * attribute() const
void removeAttribute()
int error() const
void result(KJob *job)
QString errorText() const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void deleteLater()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:33:26 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.