Commit a70e1664 authored by Laurent Montel's avatar Laurent Montel 😁

oops forgot files :)

CCMAIL: faure@kde.org
parent 38a2b4de
/*
Copyright (c) 2014 Sandro Knauß <knauss@kolabsys.com>
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 "createnotejob.h"
#include "createnoteplugin_debug.h"
#include <Akonadi/KMime/MessageParts>
#include <AkonadiCore/RelationCreateJob>
#include <AkonadiCore/ItemCreateJob>
#include <AkonadiCore/ItemModifyJob>
#include <AkonadiCore/Relation>
#include <KMime/Message>
#include <QApplication>
using namespace MessageViewer;
CreateNoteJob::CreateNoteJob(const KMime::Message::Ptr &notePtr, const Akonadi::Collection &collection, const Akonadi::Item &item, QObject *parent)
: KJob(parent),
mItem(item),
mCollection(collection),
mNote(notePtr)
{
}
CreateNoteJob::~CreateNoteJob()
{
}
void CreateNoteJob::start()
{
mNote.setFrom(QCoreApplication::applicationName() + QLatin1Char(' ') + QCoreApplication::applicationVersion());
mNote.setLastModifiedDate(QDateTime::currentDateTimeUtc());
if (!mItem.relations().isEmpty()) {
Akonadi::Relation relation;
foreach (const Akonadi::Relation &r, mItem.relations()) {
// assuming that GENERIC relations to emails are notes is a pretty horirific hack imo - aseigo
if (r.type() == Akonadi::Relation::GENERIC && r.right().mimeType() == Akonadi::NoteUtils::noteMimeType()) {
relation = r;
break;
}
}
if (relation.isValid()) {
Akonadi::Item item = relation.right();
item.setMimeType(Akonadi::NoteUtils::noteMimeType());
item.setPayload(mNote.message());
Akonadi::ItemModifyJob *modifyJob = new Akonadi::ItemModifyJob(item);
connect(modifyJob, &Akonadi::ItemModifyJob::result, this, &CreateNoteJob::noteUpdated);
return;
}
}
Akonadi::Item newNoteItem;
newNoteItem.setMimeType(Akonadi::NoteUtils::noteMimeType());
newNoteItem.setPayload(mNote.message());
Akonadi::ItemCreateJob *createJob = new Akonadi::ItemCreateJob(newNoteItem, mCollection);
connect(createJob, &Akonadi::ItemCreateJob::result, this, &CreateNoteJob::noteCreated);
}
void CreateNoteJob::noteCreated(KJob *job)
{
if (job->error()) {
qCWarning(CREATENOTEPLUGIN_LOG) << "Error during create new Note " << 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, &CreateNoteJob::relationCreated);
}
}
void CreateNoteJob::noteUpdated(KJob *job)
{
if (job->error()) {
setError(job->error());
setErrorText(job->errorText());
}
Q_EMIT emitResult();
}
void CreateNoteJob::relationCreated(KJob *job)
{
if (job->error()) {
qCDebug(CREATENOTEPLUGIN_LOG) << "Error during create new Note " << job->errorString();
}
Q_EMIT emitResult();
}
/*
Copyright (c) 2014 Sandro Knauß <knauss@kolabsys.com>
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 CREATENOTEJOB_H
#define CREATENOTEJOB_H
#include <KJob>
#include <AkonadiCore/Item>
#include <AkonadiCore/Collection>
#include <Akonadi/Notes/NoteUtils>
#include <kmime/kmime_message.h>
#include <QObject>
namespace MessageViewer
{
class CreateNoteJob : public KJob
{
Q_OBJECT
public:
explicit CreateNoteJob(const KMime::Message::Ptr &notePtr, const Akonadi::Collection &collection, const Akonadi::Item &item, QObject *parent = Q_NULLPTR);
~CreateNoteJob();
void start() Q_DECL_OVERRIDE;
private Q_SLOTS:
void noteCreated(KJob *job);
void noteUpdated(KJob *job);
void relationCreated(KJob *job);
private:
void createNote();
Akonadi::Item mItem;
Akonadi::Collection mCollection;
Akonadi::NoteUtils::NoteMessageWrapper mNote;
};
}
#endif
/*
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 "createtodojob.h"
#include "createtodoplugin_debug.h"
#include <Akonadi/KMime/MessageParts>
#include <AkonadiCore/ItemFetchJob>
#include <AkonadiCore/ItemFetchScope>
#include <AkonadiCore/ItemCreateJob>
#include <AkonadiCore/RelationCreateJob>
#include <KMime/Message>
using namespace MessageViewer;
CreateTodoJob::CreateTodoJob(const KCalCore::Todo::Ptr &todoPtr, const Akonadi::Collection &collection, const Akonadi::Item &item, QObject *parent)
: KJob(parent),
mItem(item),
mCollection(collection),
mTodoPtr(todoPtr)
{
}
CreateTodoJob::~CreateTodoJob()
{
qCDebug(CREATETODOPLUGIN_LOG) << " CreateTodoJob::~CreateTodoJob()";
}
void CreateTodoJob::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, &CreateTodoJob::slotFetchDone);
} else {
createTodo();
}
}
void CreateTodoJob::slotFetchDone(KJob *job)
{
Akonadi::ItemFetchJob *fetchJob = qobject_cast<Akonadi::ItemFetchJob *>(job);
if (fetchJob->items().count() == 1) {
mItem = fetchJob->items().at(0);
} else {
qCDebug(CREATETODOPLUGIN_LOG) << " createTodo Error during fetch: " << job->errorString();
Q_EMIT emitResult();
return;
}
createTodo();
}
void CreateTodoJob::createTodo()
{
if (!mItem.hasPayload<KMime::Message::Ptr>()) {
qCDebug(CREATETODOPLUGIN_LOG) << " item has not payload";
Q_EMIT emitResult();
return;
}
Akonadi::Item newTodoItem;
newTodoItem.setMimeType(KCalCore::Todo::todoMimeType());
newTodoItem.setPayload<KCalCore::Todo::Ptr>(mTodoPtr);
Akonadi::ItemCreateJob *createJob = new Akonadi::ItemCreateJob(newTodoItem, mCollection);
connect(createJob, &Akonadi::ItemCreateJob::result, this, &CreateTodoJob::todoCreated);
}
void CreateTodoJob::todoCreated(KJob *job)
{
if (job->error()) {
qCDebug(CREATETODOPLUGIN_LOG) << "Error during create new Todo " << 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, &CreateTodoJob::relationCreated);
}
}
void CreateTodoJob::relationCreated(KJob *job)
{
if (job->error()) {
qCDebug(CREATETODOPLUGIN_LOG) << "Error during create new Todo " << 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 CREATETODOJOB_H
#define CREATETODOJOB_H
#include <KJob>
#include <AkonadiCore/Item>
#include <AkonadiCore/Collection>
#include <KCalCore/Todo>
#include <QObject>
namespace MessageViewer
{
class CreateTodoJob : public KJob
{
Q_OBJECT
public:
explicit CreateTodoJob(const KCalCore::Todo::Ptr &todoPtr, const Akonadi::Collection &collection, const Akonadi::Item &item, QObject *parent = Q_NULLPTR);
~CreateTodoJob();
void start() Q_DECL_OVERRIDE;
private Q_SLOTS:
void slotFetchDone(KJob *job);
void todoCreated(KJob *job);
void relationCreated(KJob *job);
private:
void createTodo();
Akonadi::Item mItem;
Akonadi::Collection mCollection;
KCalCore::Todo::Ptr mTodoPtr;
};
}
#endif // CREATETODOJOB_H
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