Commit 7faffdf7 authored by Laurent Montel's avatar Laurent Montel 😁

Move as a job

parent 726ec6cc
......@@ -163,6 +163,7 @@ set(libmessageviewer_job_SRCS
job/createeventjob.cpp
job/attachmentencryptwithchiasmusjob.cpp
job/attachmenteditjob.cpp
job/modifymessagedisplayformatjob.cpp
)
set(libmessageviewer_SRCS
......
/*
Copyright (c) 2014 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "modifymessagedisplayformatjob.h"
#include <akonadi/itemmodifyjob.h>
#include "viewer/messagedisplayformatattribute.h"
using namespace MessageViewer;
ModifyMessageDisplayFormatJob::ModifyMessageDisplayFormatJob(QObject *parent)
: QObject(parent),
mMessageFormat(Viewer::UseGlobalSetting),
mRemoteContent(false),
mResetFormat(false)
{
}
ModifyMessageDisplayFormatJob::~ModifyMessageDisplayFormatJob()
{
}
void ModifyMessageDisplayFormatJob::setRemoteContent(bool remote)
{
mRemoteContent = remote;
}
void ModifyMessageDisplayFormatJob::setMessageFormat(Viewer::DisplayFormatMessage format)
{
mMessageFormat = format;
}
void ModifyMessageDisplayFormatJob::setResetFormat(bool resetFormat)
{
mResetFormat = resetFormat;
}
void ModifyMessageDisplayFormatJob::start()
{
if (mMessageItem.isValid()) {
if (mResetFormat) {
resetDisplayFormat();
} else {
modifyDisplayFormat();
}
} else {
qDebug()<<" messageItem doesn't exist";
deleteLater();
}
}
void ModifyMessageDisplayFormatJob::setMessageItem(const Akonadi::Item &messageItem)
{
mMessageItem = messageItem;
}
void ModifyMessageDisplayFormatJob::resetDisplayFormat()
{
mMessageItem.removeAttribute<MessageViewer::MessageDisplayFormatAttribute>();
Akonadi::ItemModifyJob *modify = new Akonadi::ItemModifyJob( mMessageItem );
modify->setIgnorePayload( true );
modify->disableRevisionCheck();
connect( modify, SIGNAL(result(KJob*)), this, SLOT(slotModifyItemDone(KJob*)) );
}
void ModifyMessageDisplayFormatJob::modifyDisplayFormat()
{
MessageViewer::MessageDisplayFormatAttribute *attr = mMessageItem.attribute<MessageViewer::MessageDisplayFormatAttribute>( Akonadi::Entity::AddIfMissing );
attr->setRemoteContent(mRemoteContent);
attr->setMessageFormat(mMessageFormat);
Akonadi::ItemModifyJob *modify = new Akonadi::ItemModifyJob( mMessageItem );
modify->setIgnorePayload( true );
modify->disableRevisionCheck();
connect( modify, SIGNAL(result(KJob*)), this, SLOT(slotModifyItemDone(KJob*)) );
}
void ModifyMessageDisplayFormatJob::slotModifyItemDone(KJob* job)
{
if ( job && job->error() ) {
kWarning() << " Error trying to change attribute:" << job->errorText();
}
deleteLater();
}
/*
Copyright (c) 2014 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef MODIFYMESSAGEDISPLAYFORMATJOB_H
#define MODIFYMESSAGEDISPLAYFORMATJOB_H
#include <QObject>
#include "viewer/viewer_p.h"
namespace MessageViewer {
class ModifyMessageDisplayFormatJob : public QObject
{
Q_OBJECT
public:
explicit ModifyMessageDisplayFormatJob(QObject *parent = 0);
~ModifyMessageDisplayFormatJob();
void setRemoteContent(bool remote);
void setMessageFormat(Viewer::DisplayFormatMessage format);
void setResetFormat(bool resetFormat);
void start();
void setMessageItem(const Akonadi::Item &messageItem);
private slots:
void slotModifyItemDone(KJob *job);
private:
void resetDisplayFormat();
void modifyDisplayFormat();
Akonadi::Item mMessageItem;
Viewer::DisplayFormatMessage mMessageFormat;
bool mRemoteContent;
bool mResetFormat;
};
}
#endif // MODIFYMESSAGEDISPLAYFORMATJOB_H
......@@ -39,6 +39,7 @@
#include "pimcommon/widgets/slidecontainer.h"
#include "messageviewer/job/attachmentencryptwithchiasmusjob.h"
#include "messageviewer/job/attachmenteditjob.h"
#include "messageviewer/job/modifymessagedisplayformatjob.h"
#ifdef MESSAGEVIEWER_READER_HTML_DEBUG
#include "htmlwriter/filehtmlwriter.h"
#include "htmlwriter/teehtmlwriter.h"
......@@ -3088,13 +3089,11 @@ void ViewerPrivate::slotToggleCaretBrowsing(bool toggle)
void ViewerPrivate::slotSaveMessageDisplayFormat()
{
if (mMessageItem.isValid()) {
MessageViewer::MessageDisplayFormatAttribute *attr = mMessageItem.attribute<MessageViewer::MessageDisplayFormatAttribute>( Akonadi::Entity::AddIfMissing );
attr->setRemoteContent(htmlLoadExtOverride());
attr->setMessageFormat(displayFormatMessageOverwrite());
Akonadi::ItemModifyJob *modify = new Akonadi::ItemModifyJob( mMessageItem );
modify->setIgnorePayload( true );
modify->disableRevisionCheck();
connect( modify, SIGNAL(result(KJob*)), this, SLOT(slotModifyItemDone(KJob*)) );
MessageViewer::ModifyMessageDisplayFormatJob *job = new MessageViewer::ModifyMessageDisplayFormatJob(this);
job->setMessageFormat(displayFormatMessageOverwrite());
job->setMessageItem(mMessageItem);
job->setRemoteContent(htmlLoadExtOverride());
job->start();
}
}
......@@ -3102,11 +3101,10 @@ void ViewerPrivate::slotResetMessageDisplayFormat()
{
if (mMessageItem.isValid()) {
if (mMessageItem.hasAttribute<MessageViewer::MessageDisplayFormatAttribute>()) {
mMessageItem.removeAttribute<MessageViewer::MessageDisplayFormatAttribute>();
Akonadi::ItemModifyJob *modify = new Akonadi::ItemModifyJob( mMessageItem );
modify->setIgnorePayload( true );
modify->disableRevisionCheck();
connect( modify, SIGNAL(result(KJob*)), this, SLOT(slotModifyItemDone(KJob*)) );
MessageViewer::ModifyMessageDisplayFormatJob *job = new MessageViewer::ModifyMessageDisplayFormatJob(this);
job->setMessageItem(mMessageItem);
job->setResetFormat(true);
job->start();
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment