Messagelib

modifymessagedisplayformatjob.cpp
1 /*
2  SPDX-FileCopyrightText: 2014-2021 Laurent Montel <[email protected]>
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 
15 using namespace MessageViewer;
16 ModifyMessageDisplayFormatJob::ModifyMessageDisplayFormatJob(Akonadi::Session *session, QObject *parent)
17  : QObject(parent)
18  , mSession(session)
19 {
20 }
21 
22 ModifyMessageDisplayFormatJob::~ModifyMessageDisplayFormatJob() = default;
23 
24 void ModifyMessageDisplayFormatJob::setRemoteContent(bool remote)
25 {
26  mRemoteContent = remote;
27 }
28 
29 void ModifyMessageDisplayFormatJob::setMessageFormat(Viewer::DisplayFormatMessage format)
30 {
31  mMessageFormat = format;
32 }
33 
34 void ModifyMessageDisplayFormatJob::setResetFormat(bool resetFormat)
35 {
36  mResetFormat = resetFormat;
37 }
38 
39 void 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";
49  deleteLater();
50  }
51 }
52 
53 void ModifyMessageDisplayFormatJob::setMessageItem(const Akonadi::Item &messageItem)
54 {
55  mMessageItem = messageItem;
56 }
57 
58 void 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 
67 void 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 
78 void ModifyMessageDisplayFormatJob::slotModifyItemDone(KJob *job)
79 {
80  if (job && job->error()) {
81  qCWarning(MESSAGEVIEWER_LOG) << " Error trying to change attribute:" << job->errorText();
82  }
83  deleteLater();
84 }
void deleteLater()
void removeAttribute(const QByteArray &name)
The MessageDisplayFormatAttribute class.
void result(KJob *job)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString errorText() const
int error() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Dec 5 2021 23:04:54 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.