Commit 38a2b4de authored by Laurent Montel's avatar Laurent Montel 😁

Move class here

parent 2aba5fc7
......@@ -49,9 +49,9 @@ set_tests_properties(messageviewerplugins-todoedittest PROPERTIES ENVIRONMENT "L
add_messageviewer_viewerplugin_widget_unittest(eventedittest.cpp "../createeventplugin/eventedit.cpp;../createeventplugin/eventdatetimewidget.cpp")
add_messageviewer_viewerplugin_widget_unittest(eventdatetimewidgettest.cpp "../createeventplugin/eventdatetimewidget.cpp")
add_messageviewer_viewerplugin_unittest(viewerplugincreateeventtest.cpp "../createeventplugin/eventdatetimewidget.cpp;../createeventplugin/eventedit.cpp;../createeventplugin/viewerplugincreateevent.cpp;../createeventplugin/viewerplugincreateeventinterface.cpp" "")
add_messageviewer_viewerplugin_unittest(viewerplugincreatetodotest.cpp "../createtodoplugin/viewerplugincreatetodo.cpp;../createtodoplugin/viewerplugincreatetodointerface.cpp;../createtodoplugin/todoedit.cpp" "")
add_messageviewer_viewerplugin_unittest(viewerplugincreatenotetest.cpp "../createnoteplugin/noteedit.cpp;../createnoteplugin/viewerplugincreatenote.cpp;../createnoteplugin/viewerplugincreatenoteinterface.cpp" "")
add_messageviewer_viewerplugin_unittest(viewerplugincreateeventtest.cpp "../createeventplugin/createeventjob.cpp;../createeventplugin/eventdatetimewidget.cpp;../createeventplugin/eventedit.cpp;../createeventplugin/viewerplugincreateevent.cpp;../createeventplugin/viewerplugincreateeventinterface.cpp" "")
add_messageviewer_viewerplugin_unittest(viewerplugincreatetodotest.cpp "../createtodoplugin/viewerplugincreatetodo.cpp;../createtodoplugin/viewerplugincreatetodointerface.cpp;../createtodoplugin/todoedit.cpp;../createtodoplugin/createtodojob.cpp" "")
add_messageviewer_viewerplugin_unittest(viewerplugincreatenotetest.cpp "../createnoteplugin/noteedit.cpp;../createnoteplugin/viewerplugincreatenote.cpp;../createnoteplugin/viewerplugincreatenoteinterface.cpp;../createnoteplugin/createnotejob.cpp" "")
add_messageviewer_viewerplugin_unittest(viewerplugintranslatortest.cpp "../common/translatorplugin/viewerplugintranslator.cpp;../common/translatorplugin/viewerplugintranslatorinterface.cpp" "")
add_messageviewer_viewerplugin_unittest(viewerpluginexternalscriptinfotest.cpp "../externalscriptplugin/viewerpluginexternalscriptparseargument.cpp;../externalscriptplugin/viewerpluginexternalscriptinfo.cpp;../externalscriptplugin/viewerpluginexternalscriptsloadjob.cpp" "")
......
......@@ -3,6 +3,7 @@ set(messageviewer_createeventplugin_SRCS
viewerplugincreateeventinterface.cpp
eventedit.cpp
eventdatetimewidget.cpp
createeventjob.cpp
)
ecm_qt_declare_logging_category(messageviewer_createeventplugin_SRCS HEADER createeventplugin_debug.h IDENTIFIER CREATEEVENTPLUGIN_LOG CATEGORY_NAME log_createeventplugin)
......
/*
Copyright (c) 2014-2016 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 "createeventjob.h"
#include "createeventplugin_debug.h"
#include <Akonadi/KMime/MessageParts>
#include <AkonadiCore/ItemFetchJob>
#include <AkonadiCore/ItemFetchScope>
#include <AkonadiCore/ItemCreateJob>
#include <AkonadiCore/RelationCreateJob>
#include <KMime/Message>
using namespace MessageViewer;
CreateEventJob::CreateEventJob(const KCalCore::Event::Ptr &eventPtr, const Akonadi::Collection &collection, const Akonadi::Item &item, QObject *parent)
: KJob(parent),
mItem(item),
mCollection(collection),
mEventPtr(eventPtr)
{
}
CreateEventJob::~CreateEventJob()
{
}
void CreateEventJob::start()
{
// We need the full payload to attach the mail to the incidence
if (!mItem.loadedPayloadParts().contains(Akonadi::MessagePart::Body)) {
Akonadi::ItemFetchJob *job = new Akonadi::ItemFetchJob(mItem);
job->fetchScope().fetchFullPayload();
connect(job, &Akonadi::ItemFetchJob::result, this, &CreateEventJob::slotFetchDone);
} else {
createEvent();
}
}
void CreateEventJob::slotFetchDone(KJob *job)
{
Akonadi::ItemFetchJob *fetchJob = qobject_cast<Akonadi::ItemFetchJob *>(job);
if (fetchJob->items().count() == 1) {
mItem = fetchJob->items().at(0);
} else {
Q_EMIT emitResult();
return;
}
createEvent();
}
void CreateEventJob::createEvent()
{
if (!mItem.hasPayload<KMime::Message::Ptr>()) {
qCDebug(CREATEEVENTPLUGIN_LOG) << " item has not payload";
Q_EMIT emitResult();
return;
}
Akonadi::Item newEventItem;
newEventItem.setMimeType(KCalCore::Event::eventMimeType());
newEventItem.setPayload<KCalCore::Event::Ptr>(mEventPtr);
Akonadi::ItemCreateJob *createJob = new Akonadi::ItemCreateJob(newEventItem, mCollection);
connect(createJob, &Akonadi::ItemCreateJob::result, this, &CreateEventJob::eventCreated);
}
void CreateEventJob::eventCreated(KJob *job)
{
if (job->error()) {
qCDebug(CREATEEVENTPLUGIN_LOG) << "Error during create new Event " << job->errorString();
setError(job->error());
setErrorText(job->errorText());
Q_EMIT emitResult();
} else {
Akonadi::ItemCreateJob *createJob = static_cast<Akonadi::ItemCreateJob *>(job);
Akonadi::Relation relation(Akonadi::Relation::GENERIC, mItem, createJob->item());
Akonadi::RelationCreateJob *rJob = new Akonadi::RelationCreateJob(relation);
connect(rJob, &Akonadi::RelationCreateJob::result, this, &CreateEventJob::relationCreated);
}
}
void CreateEventJob::relationCreated(KJob *job)
{
if (job->error()) {
qCDebug(CREATEEVENTPLUGIN_LOG) << "Error during create new Event " << job->errorString();
}
Q_EMIT emitResult();
}
/*
Copyright (c) 2014-2016 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 CREATEEVENTJOB_H
#define CREATEEVENTJOB_H
#include <KJob>
#include <AkonadiCore/Item>
#include <AkonadiCore/Collection>
#include <KCalCore/Event>
#include <QObject>
namespace MessageViewer
{
class CreateEventJob : public KJob
{
Q_OBJECT
public:
explicit CreateEventJob(const KCalCore::Event::Ptr &eventPtr, const Akonadi::Collection &collection, const Akonadi::Item &item, QObject *parent = Q_NULLPTR);
~CreateEventJob();
void start() Q_DECL_OVERRIDE;
private Q_SLOTS:
void slotFetchDone(KJob *job);
void eventCreated(KJob *job);
void relationCreated(KJob *job);
private:
void createEvent();
Akonadi::Item mItem;
Akonadi::Collection mCollection;
KCalCore::Event::Ptr mEventPtr;
};
}
#endif
......@@ -17,6 +17,7 @@
#include "viewerplugincreateeventinterface.h"
#include "eventedit.h"
#include "createeventjob.h"
#include <KLocalizedString>
#include <KActionCollection>
......@@ -24,7 +25,6 @@
#include <QIcon>
#include <QAction>
#include <messageviewer/createeventjob.h>
using namespace MessageViewer;
......
......@@ -2,6 +2,7 @@ set(messageviewer_createnoteplugin_SRCS
viewerplugincreatenote.cpp
viewerplugincreatenoteinterface.cpp
noteedit.cpp
createnotejob.cpp
)
ecm_qt_declare_logging_category(messageviewer_createnoteplugin_SRCS HEADER createnoteplugin_debug.h IDENTIFIER CREATENOTEPLUGIN_LOG CATEGORY_NAME log_createnoteplugin)
add_library(messageviewer_createnoteplugin MODULE ${messageviewer_createnoteplugin_SRCS})
......
......@@ -17,6 +17,7 @@
#include "viewerplugincreatenoteinterface.h"
#include "noteedit.h"
#include "createnotejob.h"
#include "createnoteplugin_debug.h"
#include <KLocalizedString>
#include <KActionCollection>
......@@ -27,7 +28,6 @@
#include <ItemFetchJob>
#include <ItemFetchScope>
#include <messageviewer/createnotejob.h>
using namespace MessageViewer;
......
......@@ -2,6 +2,7 @@ set(messageviewer_createtodoplugin_SRCS
viewerplugincreatetodo.cpp
viewerplugincreatetodointerface.cpp
todoedit.cpp
createtodojob.cpp
)
ecm_qt_declare_logging_category(messageviewer_createtodoplugin_SRCS HEADER createtodoplugin_debug.h IDENTIFIER CREATETODOPLUGIN_LOG CATEGORY_NAME log_createtodoplugin)
add_library(messageviewer_createtodoplugin MODULE ${messageviewer_createtodoplugin_SRCS})
......
......@@ -17,6 +17,7 @@
#include "viewerplugincreatetodointerface.h"
#include "todoedit.h"
#include "createtodojob.h"
#include <KLocalizedString>
......@@ -24,7 +25,6 @@
#include <QHBoxLayout>
#include <QAction>
#include <messageviewer/createtodojob.h>
using namespace MessageViewer;
......
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