messagefactoryreplyjob.cpp 2.92 KB
Newer Older
Laurent Montel's avatar
Laurent Montel committed
1
/*
Laurent Montel's avatar
Laurent Montel committed
2
   Copyright (C) 2017-2019 Laurent Montel <montel@kde.org>
Laurent Montel's avatar
Laurent Montel committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library 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
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#include "messagefactoryreplyjob.h"
Laurent Montel's avatar
Laurent Montel committed
21
#include "settings/messagecomposersettings.h"
22
#include <TemplateParser/TemplateParserJob>
Laurent Montel's avatar
Laurent Montel committed
23
#include <KIdentityManagement/IdentityManager>
Laurent Montel's avatar
Laurent Montel committed
24 25 26 27

using namespace MessageComposer;

MessageFactoryReplyJob::MessageFactoryReplyJob(QObject *parent)
Laurent Montel's avatar
Laurent Montel committed
28
    : QObject(parent)
Laurent Montel's avatar
Laurent Montel committed
29 30 31 32 33 34 35 36 37
{
}

MessageFactoryReplyJob::~MessageFactoryReplyJob()
{
}

void MessageFactoryReplyJob::start()
{
Laurent Montel's avatar
Laurent Montel committed
38
    TemplateParser::TemplateParserJob *parser = new TemplateParser::TemplateParserJob(mMsg, (mReplyAll ? TemplateParser::TemplateParserJob::ReplyAll : TemplateParser::TemplateParserJob::Reply), this);
39 40 41 42
    connect(parser, &TemplateParser::TemplateParserJob::parsingDone, this, &MessageFactoryReplyJob::slotReplyDone);
    parser->setIdentityManager(mIdentityManager);
    parser->setCharsets(MessageComposerSettings::self()->preferredCharsets());
    parser->setWordWrap(MessageComposerSettings::wordWrap(), MessageComposerSettings::lineWrapWidth());
43
#if (QT_VERSION < QT_VERSION_CHECK(5, 14, 2))
44 45 46
    if (MessageComposer::MessageComposerSettings::quoteSelectionOnly()) {
        parser->setSelection(mSelection);
    }
47
#endif
48 49 50 51
    parser->setAllowDecryption(true);
    if (!mTemplate.isEmpty()) {
        parser->process(mTemplate, mOrigMsg);
    } else {
Laurent Montel's avatar
Laurent Montel committed
52
        parser->process(mOrigMsg, mCollection.id());
53 54 55 56 57
    }
}

void MessageFactoryReplyJob::slotReplyDone()
{
Laurent Montel's avatar
Laurent Montel committed
58
    Q_EMIT replyDone(mMsg, mReplyAll);
Laurent Montel's avatar
Laurent Montel committed
59 60 61
    deleteLater();
}

62 63 64 65 66
void MessageFactoryReplyJob::setCollection(const Akonadi::Collection &collection)
{
    mCollection = collection;
}

67 68 69 70 71
void MessageFactoryReplyJob::setReplyAll(bool replyAll)
{
    mReplyAll = replyAll;
}

Laurent Montel's avatar
Laurent Montel committed
72 73 74 75 76 77 78 79 80
void MessageFactoryReplyJob::setMsg(const KMime::Message::Ptr &msg)
{
    mMsg = msg;
}

void MessageFactoryReplyJob::setTemplate(const QString &tmpl)
{
    mTemplate = tmpl;
}
Laurent Montel's avatar
Laurent Montel committed
81

Laurent Montel's avatar
Laurent Montel committed
82 83 84 85 86 87 88 89 90 91 92 93 94
void MessageFactoryReplyJob::setSelection(const QString &selection)
{
    mSelection = selection;
}

void MessageFactoryReplyJob::setOrigMsg(const KMime::Message::Ptr &origMsg)
{
    mOrigMsg = origMsg;
}

void MessageFactoryReplyJob::setIdentityManager(KIdentityManagement::IdentityManager *identityManager)
{
    mIdentityManager = identityManager;
Laurent Montel's avatar
Laurent Montel committed
95
}