Create job when we compose new message

wilder-work
Montel Laurent 9 years ago
parent 74830bca29
commit 1fe136b94e
  1. 1
      src/CMakeLists.txt
  2. 67
      src/job/composenewmessagejob.cpp
  3. 40
      src/job/composenewmessagejob.h
  4. 26
      src/kmmainwidget.cpp

@ -129,6 +129,7 @@ set(kmailprivate_job_LIB_SRCS
job/markallmessagesasreadinfolderandsubfolderjob.cpp
job/removeduplicatemessageinfolderandsubfolderjob.cpp
job/handleclickedurljob.cpp
job/composenewmessagejob.cpp
)
set(kmailprivate_widgets_LIB_SRCS

@ -0,0 +1,67 @@
/*
Copyright (C) 2017 Laurent Montel <montel@kde.org>
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 "composenewmessagejob.h"
#include "kmkernel.h"
#include "composer.h"
#include "editor/kmcomposerwin.h"
#include <KMime/Message>
#include <MessageComposer/MessageHelper>
#include <TemplateParser/TemplateParser>
ComposeNewMessageJob::ComposeNewMessageJob(QObject *parent)
: QObject(parent)
{
}
ComposeNewMessageJob::~ComposeNewMessageJob()
{
}
void ComposeNewMessageJob::start()
{
KMime::Message::Ptr msg(new KMime::Message());
const uint identity = mFolder ? mFolder->identity() : 0;
MessageHelper::initHeader(msg, KMKernel::self()->identityManager(), identity);
TemplateParser::TemplateParser parser(msg, TemplateParser::TemplateParser::NewMessage);
parser.setIdentityManager(KMKernel::self()->identityManager());
if (mFolder) {
parser.process(msg, mFolder->collection());
} else {
parser.process(KMime::Message::Ptr(), Akonadi::Collection());
}
KMail::Composer *win = KMail::makeComposer(msg, false, false, KMail::Composer::New, identity);
if (mFolder) {
win->setCollectionForNewMessage(mFolder->collection());
}
bool forceCursorPosition = parser.cursorPositionWasSet();
if (forceCursorPosition) {
win->setFocusToEditor();
}
win->show();
}
void ComposeNewMessageJob::setFolder(const QSharedPointer<MailCommon::FolderCollection> &folder)
{
mFolder = folder;
}

@ -0,0 +1,40 @@
/*
Copyright (C) 2017 Laurent Montel <montel@kde.org>
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.
*/
#ifndef COMPOSENEWMESSAGEJOB_H
#define COMPOSENEWMESSAGEJOB_H
#include <QObject>
#include <QSharedPointer>
#include <MailCommon/FolderCollection>
class ComposeNewMessageJob : public QObject
{
Q_OBJECT
public:
explicit ComposeNewMessageJob(QObject *parent = nullptr);
~ComposeNewMessageJob();
void start();
void setFolder(const QSharedPointer<MailCommon::FolderCollection> &folder);
private:
QSharedPointer<MailCommon::FolderCollection> mFolder;
};
#endif // COMPOSENEWMESSAGEJOB_H

@ -21,6 +21,7 @@
// KMail includes
#include "kmreadermainwin.h"
#include "job/composenewmessagejob.h"
#include "editor/composer.h"
#include "searchdialog/searchwindow.h"
#include "widgets/vacationscriptindicatorwidget.h"
@ -1311,28 +1312,9 @@ void KMMainWidget::slotCheckMailOnStartup()
void KMMainWidget::slotCompose()
{
KMime::Message::Ptr msg(new KMime::Message());
bool forceCursorPosition = false;
const uint identity = mCurrentFolder ? mCurrentFolder->identity() : 0;
MessageHelper::initHeader(msg, KMKernel::self()->identityManager(), identity);
TemplateParser::TemplateParser parser(msg, TemplateParser::TemplateParser::NewMessage);
parser.setIdentityManager(KMKernel::self()->identityManager());
if (mCurrentFolder) {
parser.process(msg, mCurrentFolder->collection());
} else {
parser.process(KMime::Message::Ptr(), Akonadi::Collection());
}
KMail::Composer *win = KMail::makeComposer(msg, false, false, KMail::Composer::New, identity);
if (mCurrentFolder) {
win->setCollectionForNewMessage(mCurrentFolder->collection());
}
forceCursorPosition = parser.cursorPositionWasSet();
if (forceCursorPosition) {
win->setFocusToEditor();
}
win->show();
ComposeNewMessageJob *job = new ComposeNewMessageJob;
job->setFolder(mCurrentFolder);
job->start();
}
//-----------------------------------------------------------------------------

Loading…
Cancel
Save