File indexing completed on 2024-10-27 04:51:00
0001 /* 0002 SPDX-FileCopyrightText: 2017-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "kmcomposercreatenewcomposerjob.h" 0008 #include "editor/kmcomposerwin.h" 0009 #include "kmkernel.h" 0010 #include <MessageComposer/Composer> 0011 0012 #include <MessageComposer/MessageHelper> 0013 #include <TemplateParser/TemplateParserJob> 0014 0015 KMComposerCreateNewComposerJob::KMComposerCreateNewComposerJob(QObject *parent) 0016 : QObject(parent) 0017 { 0018 } 0019 0020 KMComposerCreateNewComposerJob::~KMComposerCreateNewComposerJob() = default; 0021 0022 void KMComposerCreateNewComposerJob::start() 0023 { 0024 mMsg = KMime::Message::Ptr(new KMime::Message()); 0025 0026 MessageHelper::initHeader(mMsg, KMKernel::self()->identityManager(), mCurrentIdentity); 0027 auto parser = new TemplateParser::TemplateParserJob(mMsg, TemplateParser::TemplateParserJob::NewMessage, this); 0028 connect(parser, &TemplateParser::TemplateParserJob::parsingDone, this, &KMComposerCreateNewComposerJob::slotCreateNewComposer); 0029 parser->setIdentityManager(KMKernel::self()->identityManager()); 0030 parser->process(mMsg, mCollectionForNewMessage.id()); 0031 } 0032 0033 void KMComposerCreateNewComposerJob::slotCreateNewComposer(bool forceCursorPosition) 0034 { 0035 KMail::Composer *win = KMComposerWin::create(mMsg, false, false, KMail::Composer::New, mCurrentIdentity); 0036 win->setCollectionForNewMessage(mCollectionForNewMessage); 0037 if (forceCursorPosition) { 0038 win->setFocusToEditor(); 0039 } 0040 win->show(); 0041 deleteLater(); 0042 } 0043 0044 void KMComposerCreateNewComposerJob::setCurrentIdentity(uint currentIdentity) 0045 { 0046 mCurrentIdentity = currentIdentity; 0047 } 0048 0049 void KMComposerCreateNewComposerJob::setCollectionForNewMessage(const Akonadi::Collection &collectionForNewMessage) 0050 { 0051 mCollectionForNewMessage = collectionForNewMessage; 0052 } 0053 0054 #include "moc_kmcomposercreatenewcomposerjob.cpp"